Archive: runas does not wait the finish of child process


runas does not wait the finish of child process
Hello everybody,

I want to run a batch file (sqlcmd.exe with some sql scripts) under a different user account other than currently logged in.
I know runas plugin and already tried it.
There are some issues with runas plugin.
First of all it does not wait until the end of the process that it started. Second issue is, I need to get output of the child process (error hadling, logging etc. ). It would be also nice not to see any external window ( command prompt ) popping up.

Do you know any alternative to runas.
Welcome all suggestions.
Thank you

Selim


There is an alternative which at
http://nsis.sourceforge.net/File:RunAs.zip

Stu


Thanks Afrow
I have extracted it under plugins dir. Nothing seems wrong, but whenever I try to use RunAs::RunAs It returns "error".

Selim


Afrow, why are you doing

while (WaitForSingleObject(processInfo.hProcess, 500) == WAIT_TIMEOUT)

instead of just
WaitForSingleObject(processInfo.hProcess, INFINITE)

to wait for the child process? If you want to wait without the gui locking up, you must use MsgWaitForMultipleObjects or something like that.

Also not sure why you are calling LookupAccountName, CreateProcessWithLogonW will fail if the login is wrong so no point in checking yourself first is there?