Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

migrated from stackoverflow.com Jul 20 '11 at 19:06

This question came from our site for professional and enthusiast programmers.

    
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 Jul 20 '11 at 19:09
    
Perhaps I should have said "wait for it to finish". I want runas to return when the program finishes. –  e40 Jul 20 '11 at 19:11
    
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 Jul 20 '11 at 19:16
    
Did you tried using cmd /wait runas -"arg..." ????? –  Diogo Jul 20 '11 at 19:17
    
cmd /wait ... doesn't work because runas itself exits immediately. –  e40 Jul 20 '11 at 19:18
show 3 more comments

1 Answer

RunAs does not elevate a process, but merely runs the process with target user credentials. But this does not run the process with an elevated token. What you are trying to do with Runas is impossible.

To do this, you need to use either PowerShell, VBScript or download the Elevation PowerToys from Technet.

Edit:

For example, type:

runas /user:<i>Workadmin</i> cmd

Then run fsutils, which requires administrator privileges; access denied.

Or try:

runas /user:<i>workadmin</i> "mmc.exe gpedit.msc"

Access denied.

I'm surprised you haven't noticed this because it causes all sorts of issues when running scripts. If scripts launch other scripts which then requires elevated permissions, then it will break. This is also an issue with VBScripts and PowerShell scripts.

share|improve this answer
    
Are you sure? By running under the context of a user with the credentials you need, it gives the process elevated status - I use this frequently :/ –  William Hilsum Aug 12 '11 at 10:04
    
2008 R2 has UAC. If UAC is off, then yes. If it is on, then you are wrong. –  surfasb Aug 12 '11 at 10:05
    
I agree with William. I use this all the time and get elevated status and UAC is on. –  e40 Sep 4 '11 at 17:32
    
Ah nm. You are using the builtin Admin account. The built Admin account has auto-elevate on by default. It is off on my machine and I just assumed it was off by default on the Server editions. –  surfasb Sep 4 '11 at 20:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.