I need to register a Shell Extension for Windows, which should be able to process files and folders with names in any language.
Unfortunately, Windows seems to run it's shell extensions through a command prompt, and thus parameters are transferred not in Unicode, but in the codepage of the command prompt, which is almost always bad. I know Windows has an API function GetCommandLineW, but since the program in question is written in Java, using it would necessitate clunky JNA/JNI code, which I'm trying to avoid.
Setting the default codepage for the whole OS does not seems to be a viable option, as the only option I've found was setting HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage\OEMCP, which reportedly can make the system refuse to boot - a big no-no, as we're talking about production machines.
I have tried setting my shell extensions command to something like
chcp 65001 & "C:\path\to\java\javaw.exe" -jar "C:\path\to\program\program.jar" "%1"
or variations with or without %SystemRoot%, > nul etc. but all result in the same - when executing the shell extension a command prompt window flashes, but my program never gets called.
The next step was to create a simple batch file:
chcp 65001
"C:\path\to\java\javaw.exe" -jar "C:\path\to\program\program.jar" "%1"
and changing the shell extension command to:
"C:\path\to\program\batch.bat" "%1"
But whenever I tried to run this I would get an error message
The system could not read from the specified device
Which leads me to believe the parameter was garbled by the shell extension execution before reaching the batch file, at which point it could not be saved.
So my question is - is there a sane way to ask Windows to pass arguments in Unicode (or any other codepage) when running a shell extension? Or is the only option to use the native API provided by GetCommandLineW?