runas - Run as a different user
Table of Contents
The runas command starts a program as a different user account from the one you are currently signed in with.
Use it when you normally work as a standard user but need to run one task with an administrator account, or when you want to run a tool with a domain account.
Basic syntax of runas
runas /user:<user name> "<program to run>"
For /user, specify the account to run as. Use user@domain or domain\user for a domain account, and computername\user for a local account. The user@domain form (UPN) works only for domain accounts.
Enclose the program to start in double quotation marks.
Start Command Prompt as another user
The most basic use is to start Command Prompt as a different user.
runas /user:PC01\admin2 cmd
After you type the password and press Enter, a Command Prompt for that user opens in a new window. The password is not displayed as you type.
Run whoami in that window to confirm which user it is running as.
Run a program with arguments or spaces in the path
If you want to pass arguments, or the path contains spaces, enclose the whole command in double quotation marks and write the inner double quotation marks as \".
runas /user:PC01\admin2 "notepad C:\work\memo.txt"
runas /user:PC01\admin2 "\"C:\Program Files\MyTool\tool.exe\" /option"
If the quotation marks do not work, put the program in a path without spaces, or first open a Command Prompt with runas /user:... cmd and run the program from there. This makes quoting problems easier to avoid.
Option reference
| Option | Description |
|---|---|
/user:<user name> | Specifies the user account to run as (required) |
/profile | Loads the user profile (default) |
/noprofile | Does not load the user profile. Starts faster, but some apps do not work |
/env | Uses the current environment (such as environment variables) instead of the user’s own |
/netonly | Uses the specified credentials only for remote access over the network |
/savecred | Saves the credentials so you do not have to type the password again |
/smartcard | Specifies the credentials with a smart card |
/savecred cannot be used on Windows Home editions. It can be used on editions other than Home.
Use different credentials for network access only with /netonly
With /netonly, local programs keep running as your current user, and the specified account is used only when connecting to shared folders or servers on the network.
runas /netonly /user:CORP\taro cmd
This is handy when you need to reach a file server in another domain but your PC does not belong to that domain. The local user does not change, so whoami still shows the original user.
With /netonly, the credentials are not verified when the program starts. Even if you mistype the password, the program starts, and you get an error only when you actually connect to a shared folder or similar.
You cannot put the password in a batch file
runas has no option for passing the password on the command line. It always prompts for it, so writing runas in a batch file cannot automate the password entry.
If you really want to skip typing it, you can:
- Register a task in Task Scheduler (
schtasks) with the user to run as - Use
/savecredto store the credentials (read the warning below first)
Credentials saved with /savecred are stored on that computer. After that, anyone signed in with the same Windows account can run programs as that user without a password. Never use it with administrator accounts on shared PCs or in environments others can access.
When you want to run as administrator
If you specify another account that has administrator rights, the program runs with that account’s rights. Depending on your UAC settings, it may start with a restricted, non-elevated token.
runas /user:PC01\Administrator cmd
However, specifying your own current user does not elevate to administrator rights. To run as an administrator with your current account, open Command Prompt with “Run as administrator”.
The built-in Administrator account in Windows 10 / 11 is disabled by default. If you have not enabled it, you cannot sign in with it.
Common errors
| Message / error number | Main cause and fix |
|---|---|
| Error 1326 (user name or password is incorrect) | Check the spelling of the user name, the domain name, and the password |
| Error 1327 (account restriction) | Accounts with an empty password cannot be used by default. Set a password |
| Error 1058 (the service cannot be started) | The Secondary Logon service is disabled. Enable and start the service |
| “The system cannot find the file specified” | Check the program path and how you quoted it |
You can check the state of the Secondary Logon service with sc query seclogon.
sc query seclogon
Summary
| Goal | Command |
|---|---|
| Run a program as another user | runas /user:user "program" |
| Open Command Prompt as another user | runas /user:user cmd |
| Use other credentials for network access only | runas /netonly /user:user cmd |
| Save credentials to skip typing them next time | runas /savecred /user:user "..." |
| Check which user you are running as | whoami |