coreybutler / node-windows

Windows support for Node.JS scripts (daemons, eventlog, UAC, etc).
Other
2.82k stars 356 forks source link

Elevate script not executing correctly #185

Open Ge-lx opened 7 years ago

Ge-lx commented 7 years ago

While testing your package I noticed that while the service was installed and removed correctly, error messages popped up whenever it tried to monitor, stop or start the service.

While diagnosing that error (I assumed was on my end) I noticed that the error-dialog was opened by the elevate.vbs script. Trying it separately gave the same result. I'm running on Windows10 with Node 8.4.0.

After some testing it seems to me that the "ShellExecute" command was trying to find the NET command in the current working directory. Maybe this is because the original script split the passed command into the executable file and its arguments.

For my own project I changed the elevate script to the following:

Set Shell = CreateObject("Shell.Application")
Set WShell = WScript.CreateObject("WScript.Shell")
Set ProcEnv = WShell.Environment("PROCESS")

cmd = ProcEnv("CMD")

If (WScript.Arguments.Count >= 1) Then
  Shell.ShellExecute "cmd", "/c ""%cmd%""", "", "runas", 0
Else
  WScript.Quit
End If

This solution spawns another shell and passes the command to it as a whole. This problem doesn't seem to be very common (at least I don't see another issue describing it) so idk if you want to look into this.

Thanks for the nice tool, Gelx