2

Is it possible to continue runas /u:domain\admin command with followup commands in a new CMD.EXE window?

I tried this but it didn't work: Runas different user to launch CMD and run command

What I want is to run msra /offerra using CMD.EXE, however I need to first run CMD as another user with admin privileges using runas as shown above.

1
  • My commands had a syntax error. I fixed it.
    – Dennis
    Mar 4, 2013 at 16:01

2 Answers 2

1

Those instructions were wrong and have been fixed. Here's the usage for runas:

RUNAS USAGE:

RUNAS [ [/noprofile | /profile] [/env] [/savecred | /netonly] ]
        /user:<UserName> program

RUNAS [ [/noprofile | /profile] [/env] [/savecred] ]
        /smartcard [/user:<UserName>] program

RUNAS /trustlevel:<TrustLevel> program

Notice that in all three variations, you can specify only a program to be run, nothing else. They mean it: You cannot specify any arguments to the program as separate words. Any arguments must be embedded into the "program" string with surrounding quotes.

Also not made clear is that runas will not pass the current directories; it always starts in C:\Windows\System32. So any program you specify must either be in a PATH directory or given as a full path. You cannot use a relative path. And of course, any ACLs on that executable or the directories on its path must allow access by the user you'd like to run it as.

The good news is that runas will accept a .cmd file as a "program".

As a practical matter, what this means is that to do what you want, you'll probably want to create a .cmd file in a directory both users can access, then pass the full path. For example:

runas /u:Fred "C:\Users\Public\foo.cmd"

The final wrinkle is that runas can start a program as another user, but it can't elevate. There's no way to cause it to generate the UAC prompt. If you'd like to run something "as administrator" using runas, you'll have to enable the builtin Administrator account, which always runs elevated anyway, and specify that user name.

If that's not going to work for you and you need a generalized ability to pass arguments and/or current directories or if you need to run something elevated as something other than Administrator, you'll need a genuine su, like this one.

3

This is what you would need to put into the BAT command:

C:\windows\system32\runas.exe /u:domain\username "cmd /c Start /B %windir%\system32\msra.exe /offerra"

1
  • Wau....it sure works...no elevation
    – MrCalvin
    Mar 20, 2017 at 12:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .