Windows Spawn Child Process w/ Elevated Privileges

2,120 views
Skip to first unread message

jeff.m...@gmail.com

unread,
Dec 31, 2013, 4:45:19 AM12/31/13
to nod...@googlegroups.com
I need to launch an external program, but I'm hitting a roadblock because that external program requires elevated privileges. Normally I would just do this:

require('child_process').spawn('C:\\Users\\me\\AppData\\Local\\Temp\\1131128-16232-bid56z__some_installer.exe');

But this throws an error because the external program requires elevated privileges. Some have suggested that I use the "runas" command, but I haven't had much success yet. No error is thrown, but the external program doesn't run either.

require('child_process').spawn('runas', ['/user:my_machine_name\\administrator', 'C:\\Users\\me\\AppData\\Local\\Temp\\1131130-18300-1wol3cr__some_installer.exe']);

I've also been trying the node-window module's "elevate" method. It seems to use batch and VB scripts to do its magic, and it comes very close to solving my problem. The issue with this solution is that the child process's "close" and "exit" events seem to trigger immediately, and I lose all communication with the child process. I presume this is because the child process is aware of only the batch cmd or vbs and not my actual external program.

For the moment, I'm at a dead end. I'm very much hoping someone has an ingenious idea.

Alex Kocharin

unread,
Dec 31, 2013, 12:59:56 PM12/31/13
to nod...@googlegroups.com
 
What about starting node.js itself with elevated privileges? (and possibly dropping them later if they aren't needed)
 
 
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
 
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

jeff.m...@gmail.com

unread,
Dec 31, 2013, 1:34:00 PM12/31/13
to nod...@googlegroups.com, al...@kocharin.ru
Can I do that programically? I'd rather not require that users must always right-click "run as administrator".

Alex Kocharin

unread,
Dec 31, 2013, 2:27:48 PM12/31/13
to nod...@googlegroups.com
 
Why not?
 
If user is about to run a potentially dangerous program (as all privileged programs are), he must confirm that he is intended to do so.
 
 

jeff.m...@gmail.com

unread,
Dec 31, 2013, 4:24:23 PM12/31/13
to nod...@googlegroups.com, al...@kocharin.ru
From a usability perspective, the ideal would be that the user is prompted for elevated privileges only when he takes an action within my node program that actually requires those privileges. The second best option would be if the user was prompted for elevated privileges when they first start the node program. The least ideal is if the user isn't prompted at all, that it would be up to the user to always remember to start the program by right-click run as administrator. This is the least ideal because it puts to the burden on the user to remember to always start the program in a non-typical way.

So, to get back to my original question, right now if I try to spawn a child process where the program being spawned requires elevated privileges (example code in my original message), the current behavior is that the user is not prompted for those privileges, and instead the node program crashes with an error. How can I get my node program to request those privileges instead of just dying?
Reply all
Reply to author
Forward
0 new messages