6
4
That is, I want runas to exit only after the program that it runs exits.
There is no /wait
argument to runas.exe. I've tried lots of permutations of start /wait
with it and nothing works.
I have to use runas
because I need elevated privileges for the program, so I need to start it like this:
runas /user:administrator /savedcred /env update.exe
where update.exe
is my program. runas
is being called from a Cygwin Bash, as well, to make it even more complicated.
I'm on Server 2008 R2.
Well, this is one way to solve it. It uses the Sysinternals
pslist
program and Bash:
do_update()
{
if test -d c:/; then
case `hostname` in
thor*)
update="runas /user:administrator /savedcred /env \".\\update.exe\""
;;
*) update="./update.exe" ;;
esac
$update
while pslist -e update > /dev/null 2>&1; do
echo waiting for update.exe to finish...
sleep 3
done
else
./update.sh
fi
}
It is horribly hacky, though, mainly because it cannot get the exit status of the program back to the caller. That is a huge problem, IMO.
What do you mean for program to be started? There is process allocated etc, ready to receive windows messages, has a window showing, etc. There are different levels of "started". – earlNameless – 2011-07-20T19:09:50.003
Perhaps I should have said "wait for it to finish". I want runas to return when the program finishes. – e40 – 2011-07-20T19:11:07.483
Elevated privileges should persist through a programs run time regardless of whether or not RunAs is still running. Are you experiencing specific issues that seem to indicate otherwise? If so, please detail. – music2myear – 2011-07-20T19:16:28.090
Did you tried using cmd /wait runas -"arg..." ????? – Diogo – 2011-07-20T19:17:27.270
cmd /wait ... doesn't work because runas itself exits immediately. – e40 – 2011-07-20T19:18:27.340
@music2myear The issue isn't with the elevation. It's with the waiting. – e40 – 2011-07-20T19:18:58.650
What is NOT working? What is it not doing that you want it to do (meaning update.exe)? – KCotreau – 2011-07-20T19:26:53.107
@KCotreau It is not waiting. – e40 – 2011-07-20T19:40:36.633