The command RunAs can be utilized to execute applications and instructions as a unique person than the one signed in. Runas can be utilized on all Home windows variations and dates again to Home windows 2000. You possibly can usually right-click on a program within the person interface and choose “Run as administrator”. Which is mainly the identical conduct.
Directors usually use runas
to execute instructions or different duties with admin privileges whereas they’re logged in to an account with out administrator privileges. However the command is just not restricted to admins, you can too use the command to execute applications as one other person.
On this article, we’re going to check out learn how to use the Runas command.
The right way to use RunAs
The RunAs command comes with completely different parameters that we will use to execute applications as a unique person. However earlier than we dive into the completely different choices, let’s first check out a fast instance of learn how to execute a command as administrator.
To open the command immediate as administrator we solely have to specify the person, on this case, the native admin account, and this system that we wish to run, cmd on this case.
# Begin cmd as admin runas /person:admin cmd
After you’ve typed the command, you’ll be prompted for the password after which the command might be executed.
Parameters
With the fundamentals defined, lets take a more in-depth take a look at the completely different choices we’ve got. There are a few parameters that we will use with the runas command:
Parameter | Description |
---|---|
/person: | Specifies the person account that you just wish to use |
/noprofile | Don’t load the person’s profile, it will make the appliance load quicker. By default /profile is used |
/env | Use the present community surroundings as an alternative of person’s native surroundings |
/netonly | Credentials are just for distant entry |
/savecred | Save the password within the person’s profile so it may be used later (safety threat!) |
/smartcard | Use this selection if you’re utilizing good playing cards for authentication |
/showtrustlevel | Present accessible belief ranges |
/trustlevel | Trustlevel to run this system on |
The command at all times begins with the parameters that you just wish to use, observe by the command that you just wish to execute. The /person:
parameter is after all required and specifies the person that you just wish to run the command as.
# Runas utilization runas <parameters> /person:<username> <command>
The parameter /savecred
shops the credentials (username and password) within the person’s profile underneath %appdatapercentMicrosoftCredentials. Now, this might sound helpful for scripts and so on, however it’s mainly a giant safety threat. There’s nothing to cease the person or different applications from utilizing these credentials for one more process. So be actually cautious when utilizing this selection.
RunAs Examples
Beneath I will provide you with a few examples of learn how to use the runas command.
Run as (area) administrator
A standard use case for the command is to execute applications or open administrative instruments with administrator privilege. You possibly can both use the native admin account or the area admin account for this.
# Run commandprompt as native admin Runas /person:administrator cmd # Run commandprompt as area admin Runas /person:lazyadminadministrator cmd
Open an MMC console as admin
If you wish to open the providers.msc as administrator you possibly can’t merely specify providers.msc as this system parameter. You have to so as to add MMC in entrance of the command:
# Open providers.msc Runas /person:administrator "MMC providers.msc"
Open a program as one other person
If you kind chrome.exe within the run dialog (Home windows key + R), the appliance will open. However while you wish to run these functions as a unique person, you have to to specify the total path of the functions:
Runas /person:administrator "C:Program FilesGoogleChromeApplicationchrome.exe"
Some applications can’t be opened as a unique person. For instance, it’s not doable to open explorer or printers as administator (there’s a workaround although).
PowerShell RunAs
The runas command is previous and can be utilized in PowerShell. However there may be additionally a PowerShell equal that we will use to run PowerShell scripts and instructions as a unique person. To run instructions as a unique person we merely open a brand new PowerShell window throughout the different person context.
If you wish to run a PowerShell script or command as an administrator you need to use the parameter -Verb runAs. You don’t have to specify the person administrator. It’s additionally doable to run a script or command as a unique person. For this, we might want to use the verb RunAsUser
# Run as admin Begin-Course of powershell -Verb RunAs # Run as different person Begin-Course of powershell -Verb RunAsUser
To produce the credentials for the administrator account you possibly can both retailer the credentials in a variable, helpful if you should use it later once more. Or simply use a single-line command
# Retailer the credentials $Cred = (Get-Credential) Begin-Course of Powershell "-File c:pathtoscript.ps1" -Credential $Cred Begin-Course of Powershell "-File c:pathtoscript.ps1" -Credential (Get-Credential)
Wrapping Up
Runas is a straightforward command that’s usually utilized by directors to shortly open administrative instruments. Simply watch out with storing the credentials.
If in case you have any questions, simply drop a remark under.