Можно ли продолжить запуск команды runas / u: domain \ admin с помощью последующих команд в новом окне CMD?

8779
Andreas

Можно ли продолжить runas /u:domain\adminкоманду с последующими командами в новом окне CMD.EXE?

Я попробовал это, но это не сработало: Runas другой пользователь, чтобы запустить CMD и запустить команду

Я хочу запустить msra /offerraCMD.EXE, однако сначала мне нужно запустить CMD от имени другого пользователя с правами администратора, runasкак показано выше.

2
Мои команды имели синтаксическую ошибку. Я починил это. Dennis 11 лет назад 0

2 ответа на вопрос

3
Andy

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"

Вау .... это точно работает ... нет возвышения MrCalvin 7 лет назад 0
1
Nicole Hamilton

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.

Похожие вопросы