Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utils.elevate(...) breaks if path contains Unicode characters #55

Open
robinwassen opened this issue Nov 6, 2017 · 1 comment
Open

Comments

@robinwassen
Copy link

utils.elevate(...) seems to translate paths badly if it contains Unicode characters, this is an issue for Electron applications since they are commonly installed in %AppData% and the Windows user folder is named after the user.

windows_registry_unicode

(The error message says "Could not find file X. Check the name and try again")

Steps to reproduce

  1. Create a folder containing Unicode characters
  2. Add a .bat script to that folder
  3. Try to elevate the bat script e.g. require("windows-registry").utils.elevate("C:\\שךקכ\\test.bat", "", function(res, err) { console.log(error);})

Expected outcome

The script should be executed elevated.

Actual outcome

The path becomes broken an error prompt is shown that the file could not be found.

Research

Created a console application in C++ that performs a shell execute of the bat script, similar to how windows-registry does it. The Unicode are encoded differently since there are issues with using Unicode characters in the source file, but it is the exactly same path.

This works as intended.

SHELLEXECUTEINFO shExecInfo;

shExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);

//shExecInfo.cbSize = SHELLEXECUTEINFO.size;
shExecInfo.fMask = NULL;
shExecInfo.hwnd = NULL;
shExecInfo.lpVerb = "runas";
shExecInfo.lpFile = "C:\\\u05E9\u05DA\u05E7\u05DB\\test.bat";
shExecInfo.lpParameters = "";
shExecInfo.lpDirectory = NULL;
shExecInfo.nShow = SW_SHOWNORMAL;
shExecInfo.hInstApp = NULL;
shExecInfo.lpIDList = NULL; 
shExecInfo.lpClass = NULL;
shExecInfo.hkeyClass = NULL;
shExecInfo.dwHotKey = NULL;

ShellExecuteEx(&shExecInfo);

require("fs").statSync("C:\\שךקכ\\test.bat") also works as intended, so there seems to be something that goes lost in translation when it comes to the path and elevate()

@robinwassen
Copy link
Author

Did some further research by creating my own native module, the wide string variants SHELLEXECUTEINFOW and ShellExecuteExW must be used. Node defaults to the ANSI variants.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant