node-windows icon indicating copy to clipboard operation
node-windows copied to clipboard

Can't tell if elevate was successful

Open endquote opened this issue 11 years ago • 9 comments

If I use wincmd.elevate() and a UAC prompt pops up, there doesn't seem to be a way to tell if the user declined the granting of permission. In the callback, the error, stdout, and stderr arguments are all empty.

endquote avatar Feb 18 '14 00:02 endquote

Yes, I believe it's a silent command in its current form. I don't have time to test it, but I believe a few minor changes to bin/elevate/elevate.vbs will provide the output you're looking for. Specifically, using CScript instead of WScript. I honestly don't remember why I didn't do this in the original version, but here is what I think it would need to look like:

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

cmd = ProcEnv("CMD")
app = ProcEnv("APP")
args= Right(cmd,(Len(cmd)-Len(app)))

If (CScript.Arguments.Count >= 1) Then
  Shell.ShellExecute app, args, "", "runas", 0
Else
  CScript.Quit
End If

Please let me know if that helps, and I'm sorry I can't test things out right now.

coreybutler avatar Feb 18 '14 19:02 coreybutler

Hey, thanks for checking it out. I tried that but I get the error Object required: 'CScript'. I researched this a bit and got as far as changing start wscript to start cscript in elevate.cmd, but that just popped up a console window briefly and didn't actually elevate the command.

I'm not really familiar with Windows scripting (aside from batch files...) so I'm unsure what to try next, but if you want me to check something out I'd be glad to. This also isn't a critical bug for me right now, so no big deal if it sits around a while. Thanks again for the great tool.

endquote avatar Feb 18 '14 21:02 endquote

Having the same issue here. I can't tell if the elevation was successful or not (error is null in any case), or if the child process was successful or not (not sure if there is something analogous to UNIX error codes on Windows).

Is this feasible? I have no experience on Windows system myself to work on this.

jviotti avatar Jan 05 '15 17:01 jviotti

@coreybutler I've been trying to get your suggestion working. I made use of CScript along the code and call it with start cscript as @endquote suggestion.

The following line turned out to be problematic:

Set WShell = CScript.CreateObject("CScript.Shell")

and it returned an error that said: "Microsoft VBScript runtime error: Object required: "CScript"" (the error is shown in a terminal instance that is shown for a few milliseconds, so I had to film to screen and pick the right frame in order to see it, but there is still a missing part of the error that is not visible due to the small terminal size).

After some googling, I replaced CScript.CreateObject with simply CreateObject, but I now get the following error:

Microsoft VBScript runtime error: ActiveX component can't create object: 'CScript.Shell'.

I'd appreciate is someone with experience on this can provide some feedback.

jviotti avatar Jan 06 '15 13:01 jviotti

@jviotti - which version of Windows are you running this on?

I haven't had much time for fixes on this project recently and have been re-evaluating the elevation process for the next version.

coreybutler avatar Jan 08 '15 15:01 coreybutler

@coreybutler I'm running Windows 8.1, please let me know of any news regarding this issue.

jviotti avatar Jan 08 '15 16:01 jviotti

@coreybutler first of al, thanks for this module, it's very neat :+1: +1 from me, would be really cool if I could tell if the elevation succeded.

AFAIU what happens now is if the user clicks 'no' in UAC prompt, Windows will do some some kind of emulation pretending that it can write to disk (this is my use case) but will not really do it - will not throw any EPERM errors as would happen when running without elevation, which can be a bit misleading.

(my use case for the usage of this module is creating symlinks which apparently is impossible from regular non-elevated node scripts)

jakub-g avatar Jan 20 '16 16:01 jakub-g

elevate() pops up tha UAC but doesn't do anything other than that. Win10 @32bit

black-snow avatar Jun 29 '16 15:06 black-snow

might it be of any help, https://github.com/ChristopherHaws/node-windows-elevate https://github.com/mh-cbon/aghfabsowecwn

mh-cbon avatar May 13 '17 09:05 mh-cbon