≡ Menu

Windows runas command syntax and examples

Runas is a very useful command on Windows OS. This command enables one to run a command in the context of another user account. One example scenario where this could be useful is: Suppose you have a normal user account and an administrator account on a computer and currently you are working from the normal user account. Now you want to install some software on the computer, but as you do not have admin privileges you can’t install the same from the current account. One option is to switch user and login as administrator. Instead, you can do the same by simply using runas command. You just need to launch the installer from command prompt using runas command and by providing administrator login id and password.

Let’s see the syntax of runas command with some examples.

Run a program from another user account

The command to launch a program using another user credentials is given below.

runas /user:domainname\username program

For example, if you want to open registry editor as administrator of the computer, the command would be as below.

runas /user:administrator regedit

After running the above command, you will be asked to enter the password of administrator account. After password validation, registry editor will be opened with the administrator account credentials.

To specify arguments to the program:

If you need to provide arguments to the program that need to be invoked as another user, you can put the program name and the parameters in double quotes.

runas /user:username "program argument1 argument2 ..."

For example to open the file C:\boot.ini as administrator, the command would be:

runas /user:administrator "notepad C:\boot.ini"

Running command prompt as another user :

If you have multiple commands need to be executed with administrator(or any other user )credentials, instead of running each command using runas, you can open command prompt window once as the administrator and then run all the commands in that window. Below is the command for opening a command window using runas.

runas /user:administrator cmd

Example:

C:\>runas /user:administrator cmd
Enter the password for administrator:
Attempting to start cmd as user "techblogger-pc\administrator" ...

It will launch new command window after printing the above message.

Run a batch file as administrator

To run a batch file as administrator of the computer, you need to mention the path of the batch file in the place of command in the runas syntax.

For example, to run the batch file located at c:\data\mybatchfile.bat, you need to run the below command.

runas /user:administrator C:\data\mybatchfile.bat

Some questions regarding runas command:

When I use runas command, I am getting the error ‘This program is blocked by group policy. For more information, contact your system administrator’. How can I fix this?

Administrator of your system might have disabled users to login from command prompt. In group policy editor, this setting can be found in the below node.

Computer Configuration -> Windows settings -> Security settings ->Local Policies -> User rights assignment

In the above path, look for the setting ‘Deny logon as a batch job‘. If you have administrator privileges,  you can disable this settings. Otherwise, you need to contact the system/domain administrator.

26 comments… add one
  • Rakesh

    Unable to runas administrator.
    I have only one user 'rakesh' and that user is the Administrator. When I execute this command –

    C:\Users\rakesh>runas /user:administrator cmd

    Enter the password for administrator:
    Attempting to start cmd as user "RAKESH-LAP\administrator" …
    RUNAS ERROR: Unable to run – cmd
    1327: Logon failure: user account restriction. Possible reasons are blank passwords not allowed, logon hour restrictions, or a policy restriction has been enforced.

    I enter the password for user 'rakesh'. What am I missing here?

    • n. sharma

      Hey!!
      I’m encountering the same problem. Did u get the solution.
      Please help me.

    • Ray

      If rakesh is the administrator, then the command would be runas /user:rakesh cmd

  • Techblogger

    runas is useful if the current logged in account does not have admin access. In your case you already have admin privileges. why are you doing runas admin then?

    Check if the administrator account is disabled, or the password has expired. 'Net user administrator' will show this info.

    • tecthusiast

      im having the same problem as Rakesh. regardless of whether or not im on admin already i would like a solution. i don’t care if i don’t need to do this to install something, this doesn’t work on limited users either.

      before you ask yes Secondary Logon says: Status=started; Startup Type=Automatic; Log On As=Local System.

      yes i have tried changing the password from a blank, it doesn’t accept it otherwise

      what i want is to open another cmd shell as the built in administrator.
      the error i get is:
      RUNAS ERROR: Unable to run – cmd
      1327: Logon failure: user account restriction. Possible reasons are blank passwords not allowed, logon hour restrictions, or a policy restriction has been enforced.

      no administrator does not have logon hour restrictions

      no policy restriction (to the best of my knowledge) is enabled, i’ve formatted this myself.

      this problem i running me through the walls i would really apreciate any help that could gget this fixed thank you.

    • s.smits.nl

      I’ve the exact same problem as tecthusiast described

      No solution what so ever either

  • tecthusiast

    oh and no im not connected to a domain

  • Jeff

    I’m trying to add a new user using runas, it does not work.

    C:\Users\jeff>runas /user:domain\jeff "net user /add newuser password "
    Enter the password for domain\jeff:
    Attempting to start net user /add newuser password as user "domain\jeff" ...

    A new command window flashes and it does not print any error in the main window. But I don’t see the user added.

    • Tyler

      Try chnage
      net user /add newuser password
      to
      net user newuser password /add
      It should work

  • Tyler

    I have RUNAS in my batch script and I’ve got a problem.
    First call of RUNAS works fine, but second call (after some other commands) doesn’t work. It starts program with current user, not with user I specified in RUNAS command.
    Why so?

  • Lyle

    When attempting this command, I receive the message “Enter the password for the administrator:”, which obviously I do not have, or I wouldn’t be going to this amount of trouble.
    Additionally, my command does not go straight to “C:\runas…”
    Rather, it automatically goes C:\Users\(my username)>runas, which seems like it may be the problem that sparks the program to ask for the administrator password.
    (Yes, my computer has parental controls on it which I am attempting to bypass. It is important to note that no, parents do not always have your “best interests” in mind, and as this laptop is my primary means through which I complete schoolwork I need to be able to install programs and update them at will, without needing to beg for a password. It is not nearly as simple as “just ask your parents” or “be responsible and show them you can handle it” for some people, and I do not have the time to argue with a parent whenever I need to install a program such as Evernote or change some small setting such as which programs are displayed in the taskbar.)

    • Dan S.

      I think your not understanding the command at all. The runas command is setup to allow you to run applications or the command prompt with an admin password for that machine without having to switch who is logged in. If I (your dad has admin rights to the laptop) then If I ran the runas command I could use my credentials to install or run something with admin right on your profile. So you have to have the administrator password or a users password that has admin rights to run this. You would need a different program for what you are trying to do. You would need a way to get the admin password or a way to login with admin rights.

    • grummbunger

      think like a hacker and with a hidden video cam watching you get your dad to enter the password for whatever reason you can get that he will do and capture that password. to hack is not always via computer code….

    • Jungle

      Lyle,

      It looks like your parents have created a user account for you which has less privileges (standard user). You might want to look at it another way. Lets say, you can change the Administrator password to nothing (blank) and move your user account under Administrators group (but make sure the Operating System is not Home Basic or any such lower tier OS ).
      You might want to use the “net user” command.
      First of all, do the following to change the admin password. in command prompt, type “net user Administrator *” and press enter-type a new password as required and confirm by re-typing it . Then type “runas /user:Administrator cmd”. this will open command prompt in admin mode
      1. in command prompt type, “net users” and press enter . identify your username and take not of the administrator user account
      2. type “net localgroup users” or try “net localgoup Administrators” and press enter to see which local group your user account is in. make sure you remember your username
      3. type “net localgroup Administrators {your username} /add” and press enter
      4. type “net localgroup Administrators” to confirm that your username is now under administrators group. You should now have full admin privileges to do the unthinkable.

      You might also, as a way of courtesy , not tell your parents what happened to the admin password.

      Happy learning!

  • Wissam

    the runas asked the user to insert the password, what if i want to ask to insert the user name and the passweord

  • gdv

    I used to be able to run the following two commands from the Run window (WinKey+R) in WinXP, but on Win7 the second command (delete arpcache) requires elevation (Run as administrator), even when launched from the Run window under an admin user acct:

    cmd /k ipconfig /flushdns
    cmd /k netsh interface ip delete arpcache

    I understand the basics of UAC, and from what I gather from numerous forum threads and several experiments of my own, there is simply no way to run the second command directly from the Run window (short of creating a batch file to run a “scheduled task” and running the batch file from the Run window).

    I thought maybe there would be a way to do this using Runas, but have not succeeded yet. At best, it appears I can only open an elevated Command Window using Runas, then still have to enter the “netsh interface ip delete arpcache” command in that elevated window. (…in which case, WinKey > type “cmd” > Ctrl+Shift+Enter is faster to open an elevated command window than using Runas from the Run window)

    Am I overlooking something? Is there any way to do this with a single Runas command from the Run window (WinKey+R) without using a batch file?

    (The advantage would be that the command would be stored in RunMRU, readily available for re-use in the Run window, and I can propagate it along with other favorite RunMRU commands to other computers via REG file.)

    Thanks!

  • Mariela

    I need to put the password in the same command line. How can I do that?

  • Leeroy

    How can I use this in batch files without creating a new window?

    Sort of like this, but this doesn’t work:

    @echo off
    title Ugly title with Administrator: prepended to it
    runas /trustlevel:0x20000 %0 %*

  • peter

    i have 3 user on my pc and for the one i need to log into i can not cause i forgot the password
    right now i m using guest and i am trying to reset password for the one i need to be log into iv search on youtube of how i can get into my main user ?
    administrator peter norton jr guest
    my main user is the peter norton jr but i forgot the password ?
    i tried the cmd prompt but cannot reset/change password doing something wrong?
    thank you

  • peter

    i also dont know the password for administrator or for peter norton jr
    tried sereval command prompts on how to change or reset password

  • algren

    hey, i tried for run this command which i have been create new user account before it’s called “backdoor” and password “backdoor”

    runas /user:administrator\backdoor regedit

    and i have a problem with error 740: The requested operation requires elevation.

    anyone can help me?

  • Elia

    How would I use runas in which the command and the arguments both have spaces, e.g., something like:
    runas /user:username “\”C:\Program Files\path\testit.bat\” \”first argument\””

    If the argument(s) don’t have spaces and don’t need quotes, then there is no issue and it runs, e.g.,
    runas /user:username “\”C:\Program Files\path\testit.bat\” argument”

    Or if the command does not have spaces, but the argument(s) do, then there is also no issue, e.g.,
    runas /user:username “C:\temp\testit.bat \”first argument\””

    However, when both the command and the argument(s) have spaces and need to be quoted, then it will not run.

    Note that I was able to get this to work using cmd as a wrapper so that the actual command to runas does not have spaces, but the syntax was even more ugly and contorted than above, e.g.,
    runas /user:username “cmd /Q /C \”\”C:\Program Files\path\testit.bat\” \”first argument\”\””

    Any suggestions to get this to work with the extra cmd wrapper?

    • Elia

      Correction to my question:
      Any suggestions to get this to work WITHOUT the extra cmd wrapper?

  • Benit

    Hi I am trying to launch my application using runas command using the following syntax
    runas /user:xxxx “c:\application.exe D:\” the first path is the application which i need to launch and the second command argument is the input to the launched application. But right now , it is showing error msg in ProcessShellCommand(cmdInfo) . Please suggest some alternatives

  • Roberto

    Hi, I have a service that run some scripts with administrator privileges, but the scripts work only if it was run by a simple user.
    I have change the account connection of the service, but the scripts keep been launch with administrator privileges.
    So how can I run it?

  • chris

    Hello,

    Is there a way to have the command line script launch as admin and enter the password without typing it in manually?

Leave a Comment