Using the runas command in Windows 10 to run a command as admin.

Posted: June 17, 2015. At: 11:26 PM. This was 3 years ago. Post ID: 8240
Page permalink.
WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters. These cookies expire two weeks after they are set.

The runas command in Windows 7 8 and now Windows 10 allows the unprivileged user to execute a command as a superuser. This is rather like the sudo command for Linux and UNIX. In the example below, I am executing a command on the computer BLUFOR as the user Dobbo. I am running notepad as an example.

C:\Users\mike>runas /user:BLUFOR\Dobbo notepad
Enter the password for BLUFOR\Dobbo:
Attempting to start notepad as user "BLUFOR\Dobbo" ...

You may also open a Powershell window as the administrator.

C:\Users\mike>runas /user:BLUFOR\Dobbo powershell
Enter the password for BLUFOR\Dobbo:
Attempting to start powershell as user "BLUFOR\Dobbo" ...

This is the help for the runas command. This shows the many command line parameters that may be applied to this command.

C:\Users\mike>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
 
   /noprofile        specifies that the user's profile should not be loaded.
                     This causes the application to load more quickly, but
                     can cause some applications to malfunction.
   /profile          specifies that the user's profile should be loaded.
                     This is the default.
   /env              to use current environment instead of user's.
   /netonly          use if the credentials specified are for remote
                     access only.
   /savecred         to use credentials previously saved by the user.
   /smartcard        use if the credentials are to be supplied from a
                     smartcard.
   /user             <UserName> should be in form [email protected] or DOMAIN\USER
   /showtrustlevels  displays the trust levels that can be used as arguments
                     to /trustlevel.
   /trustlevel       <Level> should be one of levels enumerated
                     in /showtrustlevels.
   program         command line for EXE.  See below for examples
 
Examples:
> runas /noprofile /user:mymachine\administrator cmd
> runas /profile /env /user:mydomain\admin "mmc %windir%\system32\dsa.msc"
> runas /env /user:[email protected] "notepad \"my file.txt\""
 
NOTE:  Enter user's password only when prompted.
NOTE:  /profile is not compatible with /netonly.
NOTE:  /savecred is not compatible with /smartcard.

I cannot run the dir command with the runas command. But this is very useful for running various commands as the administrator. Much more information on this command here: https://technet.microsoft.com/en-au/library/cc771525.aspx.

No comments have been made. Use this form to start the conversation :)

Leave a Reply