fortypoundhead.com

RUNAS

Posted On 2007-04-24 by FortyPoundHead
Keywords: Command Reference
Tags: Windows Commandline Windows 2000 Windows XP
Views: 2026


Execute a program under a different user account.

Syntax
RUNAS [/profile] [/env] [/netonly] /user:user Program

Key
/profile Option to load the user''s profile (registry)
/env Use current environment instead of user''s.
/netonly Use if the credentials specified are for RAS only.
/user Username in form USER@DOMAIN or DOMAIN\USER
(USER@DOMAIN is not compatible with /netonly)
Program The command to execute

Examples:
runas /profile /user:mymachine\administrator CMD
runas /profile /env /user:SCOT_DOMAIN\administrator NOTEPAD
runas /env /user:jDoe@swest.ss64.com "NOTEPAD \"my file.txt\""
Enter the password when prompted.

RunAs from the Windows explorer GUI
Select an executable file, Shift-Right-click and select Run As..
This option can be hidden by setting
HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer
HideRunAsVerb=1

ErrorLevel
The error level returned by RunAs is not consistent between operating systems

In Windows 2000:
- success: %ERRORLEVEL%=1
- fails: %ERRORLEVEL%=0

In Windows XP:
- success: %ERRORLEVEL%=0
- fails: %ERRORLEVEL%=1

For Example

VER | find "2000" > nul
IF %errorlevel% EQU 0 GOTO s_2000

::Running XP
RUNAS /user:jDoe@swest.ss64.com "mycommand.exe"
IF %ERRORLEVEL%==0 Echo command succeeded
goto :eof

:s_2000
::Running Windows 2000
RUNAS /user:jDoe@swest.ss64.com "mycommand.exe"
IF %ERRORLEVEL%==1 Echo command succeeded
goto :eofRunAs Reqires the "Secondary Logon" service to be running.


About the Author

FortyPoundHead has posted a total of 1974 articles.

 


Comments On This Post

No comments on this post yet!


Do you have a thought relating to this post? You can post your comment here. If you have an unrelated question, you can use the Q&A section to ask it.

Or you can drop a note to the administrators if you're not sure where you should post.


Your IP address is:54.224.155.169

Before you can post, you need to prove you are human. If you log in, this test goes away.




Recent Forum Posts

Advanced search added
dwirch posted on September 23, 2017 at about 13:44 in Site News

Job Spammer: Gaurav Mehta - AgreeYa Solutions
dwirch posted on September 22, 2017 at about 10:35 in Spammers

Job Spammer: Prutha Siri - Javelin Systems
dwirch posted on September 10, 2017 at about 6:15 in Spammers

New security implemented
dwirch posted on September 7, 2017 at about 7:16 in Site News

Malicious IP Checker Companion Tool
dwirch posted on August 12, 2017 at about 20:24 in Site News

Job Spammer: Steve Adams
dwirch posted on August 8, 2017 at about 7:44 in Spammers