# How to use the RunAs command in Windows

The command RunAs can be used to execute programs and commands as a different user than the one signed in. Runas can be used on all Windows versions and dates back to Windows 2000. You can often right-click on a program in the user interface and select “Run as administrator”. Which is basically the same behavior.

Administrators often use runas to execute commands or other tasks with admin privileges while they are logged in to an account without administrator privileges. But the command is not limited to admins, you can also use the command to execute programs as another user.

In this article, we are going to take a look at how to use the Runas command.

## How to use RunAs

The RunAs command comes with different parameters that we can use to execute programs as a different user. But before we dive into the different options, let’s first take a look at a quick example of how to execute a command as administrator.

To open the command prompt as administrator we only need to specify the user, in this case, the local admin account, and the program that we want to run, cmd in this case.

# Start cmd as admin
runas /user:admin cmd

After you have typed the command, you will be prompted for the password after which the command will be executed.

### Parameters

With the basics explained, lets take a closer look at the different options we have. There are a couple of parameters that we can use with the runas command:

The command always starts with the parameters that you want to use, follow by the command that you want to execute. The /user: parameter is of course required and specifies the user that you want to run the command as.

# Runas usage
runas <parameters> /user:<username> <command>

The parameter /savecred stores the credentials (username and password) in the user’s profile under %appdata%\Microsoft\Credentials. Now, this might seem useful for scripts etc, but it’s basically a big security risk. There is nothing to stop the user or other programs from using these credentials for another task. So be really careful when using this option.

## RunAs Examples

Below I will give you a couple of examples of how to use the runas command.

### Run as (domain) administrator

A common use case for the command is to execute programs or open administrative tools with administrator privilege. You can either use the local admin account or the domain admin account for this.

# Run commandprompt as local admin

# Run commandprompt as domain admin
Runas /user:lazyadmin\administrator cmd

### Open an MMC console as admin

If you want to open the services.msc as administrator you can’t simply specify services.msc as the program parameter. You will need to add MMC in front of the command:

# Open services.msc
Runas /user:administrator "MMC services.msc"

### Open a program as another user

When you type chrome.exe in the run dialog (Windows key + R), the application will open. But when you want to run these applications as a different user, you will need to specify the full path of the applications:

Runas /user:administrator "C:\Program Files\Google\Chrome\Application\chrome.exe"

Some programs can’t be opened as a different user. For example, it’s not possible to open explorer or printers as administator (there is a workaround though).

## PowerShell RunAs

The runas command is old and can be used in PowerShell. But there is also a PowerShell equivalent that we can use to run PowerShell scripts and commands as a different user. To run commands as a different user we simply open a new PowerShell window within the other user context.

When you want to run a PowerShell script or command as an administrator you can use the parameter -Verb runAs. You don’t need to specify the user administrator. It’s also possible to run a script or command as a different user. For this, we will need to use the verb RunAsUser

# Run as admin
Start-Process powershell -Verb RunAs

# Run as other user
Start-Process powershell -Verb RunAsUser

To supply the credentials for the administrator account you can either store the credentials in a variable, useful if you need to use it later again. Or just use a single-line command

# Store the credentials
$Cred = (Get-Credential) Start-Process Powershell "-File c:\path\to\script.ps1" -Credential$Cred

Start-Process Powershell "-File c:\path\to\script.ps1" -Credential (Get-Credential)

## Wrapping Up

Runas is a simple command that is often used by administrators to quickly open administrative tools. Just be careful with storing the credentials.

If you have any questions, just drop a comment below.

## Get more stuff like this

IT, Office365, Smart Home, PowerShell and Blogging Tips

I hate spam to, so you can unsubscribe at any time.