Windows run command as administrator cmd

I have a small script that performs the build and install process on Windows for a Bazaar repository I'm managing. I'm trying to run the script with elevated, administrative privileges from within ...

All you have to do is use the runas command to run your program as Administrator (with a caveat).

runas /user:Administrator "cmdName parameters"

In my case, this was

runas /user:Administrator "cmd.exe /C %CD%installer.cmd %CD%"

Note that you must use Quotation marks, else the runas command will gobble up the switch option to cmd.

Also note that the administrative shell (cmd.exe) starts up in the C:WindowsSystem32 folder. This isn’t what I wanted, but it was easy enough to pass in the current path to my installer, and to reference it using an absolute path.

Caveat: Enable the admin account

Using runas this way requires the administrative account to be enabled, which is not the default on Windows 7 or Vista. However, here is a great tutorial on how to enable it, in three different ways:

I myself enabled it by opening Administrative Tools, Local Security Policy, then navigating to Local PoliciesSecurity Options and changing the value of the Accounts: Administrative Account Status policy to Enabled, which is none of the three ways shown in the link.

An even easier way to accomplish this:

C:> net user Administrator /active:yes

Let’s consider several ways to run a program as an administrator in Windows 10 to fix errors: “CreateProcess failed; code 740“, “The requested operation requires elevation“, “Access is denied“, etc. that occur when running programs with limited rights (user, the guest).

By default, programs and games in Windows 10 run without administrator rights to prevent unauthorized changes to your system. But this is a common case when for the program to work correctly, it needs to be run with elevated rights (administrator), to work correctly or to execute certain commands.

⚠️ Attention: to run the program with elevated rights, you need to know the administrator password!

Content

  1. Application Icon
  2. File properties
  3. Start menu (context menu)
  4. Start menu (keyboard shortcut)
  5. Run menu
  6. Explorer Ribbon
  7. Windows Search
  8. Command prompt (CMD)
  9. PowerShell
  10. Batch file

Article in other languages:
🇪🇸 – Cómo ejecutar programa como administrador
🇷🇺 – Как запустить программу от имени администратора
🇫🇷 – Comment exécuter un programme en tant qu’administrateur
🇩🇪 – So führen Sie ein Programm als Administrator aus
🇳🇱 – Hoe Programma als administrator uitvoeren

🧐 It might be interesting:
1️⃣ 8 Ways to Run Command Prompt as Administrator
2️⃣ 7 Ways to Run PowerShell as Administrator

Application Icon

How to run the program as administrator once, using the program icon:

  1. Right click on the program icon;
  2. Select Run as administrator.

How to run program as administrator

File properties

The method is to always run the program with administrator rights using the File Properties menu.

  1. Right click on the program icon;
  2. Select Properties;
  3. Open the Compatibility tab;
  4. Check the Run this program as an administrator box;
  5. Click OK.

Run the program with administrator rights from File Properties

This setting will allow this program to run continuously with elevated rights for that user only. If you want to allow the program to run with administrator rights for all computer users, in the previous window, click the Change settings for all users button and check the Run this program as an administrator box.

Run the program with elevated rights using the context menu in the Start menu.

  1. Open the Start menu (Ctrl+ESC);
  2. Find the program icon in the All Programs list;
  3. Right-click on the program icon, select: More -> Run as administrator.

Launching a program from the Start menu is another way to launch an elevated program

In the same way, you can launch App Tiles in Windows 10, 8.

A mouse click and keyboard shortcut in the Start menu is another way to run program as administrator.

  1. Open the Start menu (Ctrl+ESC);
  2. Find the program icon in the All Programs list;
  3. Hold down the Ctrl+Shift keys and click on the program icon.

Keyboard shortcut to run the program as administrator in the Start menu

You can use Ctrl+Shift+Click shortcut on the application tile in the Start menu.

The way to run the program with full rights using the Run menu.

  1. Press the Windows+R key combination (or right-click on the Start button and select Run);
  2. Enter the command name or drag the program icon into the Run menu entry window;
  3. Press the keyboard shortcut Ctrl+Shift+Enter.

How to run a program as administrator using the Run menu

⭕ If you cannot move the program icon to the Run menu:

  1. Press and hold the Shift button, right-click on the program icon;
  2. Select Copy as path;
  3. Paste from the clipboard into the Run window (press the key combination Ctrl+V).

Explorer Ribbon

An easy way to run any program as administrator is using the Windows 10 Explorer ribbon.

🔔 If the Explorer Ribbon is not displayed in the folder menu, press Ctrl+F1.

  1. Select the program icon in Windows Explorer;
  2. In the folder menu, open the Application Tools tab;
  3. Select Run as administrator.

Run programs using the Windows Explorer Ribbon with administrator rights

Windows Search

You can also run the program with administrator rights using Windows 10 Search.

  1. Press Windows+S (or right-click on the Start button and select Search);
  2. Enter the name of the required program;
  3. On the right side of the window, click Run as administrator.

Use Windows 10 Search to run the program with full administrator rights

Run program as administrator Command prompt (CMD)

One-time launch of the program as administrator – using the Windows command line (CMD).

An easy way to start is to run Command Prompt as administrator, from which the required program is launched. But you can also run from the CMD console (with user rights) using the runas command.

  1. Run Command Prompt;
  2. Run the runas command, specifying the username with administrative rights and the full path to the file of the program to be launched;
  3. Enter the password for the user with administrative rights.
runas /user:MHelp.pro "C:totalcmdTOTALCMD.EXE"

Run the program as administrator using the Command prompt

In the example, the administrator name is MHelp.pro

Run program as administrator using PowerShell

Another way to run the program with elevated rights is by using Microsoft PowerShell.

An easy way to start is to run PowerShell as administrator and run the required program. But you can also start from the PowerShell console (with user rights) using the start-process command.

  1. Start PowerShell;
  2. Run the start-process command, specifying the full path to the file of the program to be launched;
  3. Enter the password for the user with administrative rights.
start-process "C:totalcmdTOTALCMD.EXE" –verb runas

Run the program as administrator using Microsoft PowerShell

Batch file

In some cases, using the previous methods may be inconvenient, let’s create a bat file with instructions for running the program.

A batch file is a script file in DOS, OS/2 and Microsoft Windows. It consists of a series of commands to be executed by the command-line interpreter, stored in a plain text file.

Wikipedia

  1. Launch the standard Notepad application;
  2. We indicate the required sequence of commands;
  3. In the File menu, select the Save As item;
  4. In the File name field, specify the file name and add the .bat extension;
  5. In the File type field, specify All files;
  6. Click the Save button.

Now you can run the program with administrator rights by running the created file.

Create a Batch file to run the program with system administrator rights

Find out more commands that can be used in bat files – link.


🟢 How to run the program as administrator was discussed in this article. I hope you now know how to fix error 740 or “The requested operation requires elevation” by running the program with elevated privileges in a convenient way. However, if you run into any problems while setting up, feel free to write in the comments. I will try to help.

  • Remove From My Forums
  • Question

  • Hello All,

    I would like to know if there is a way to run a java program, requiring administrator priviledges, via the Windows command line.

    Normally you would right click and then select ‘run as administrator’ — but i would like to set this as a property on the command line, so that you dont have to right click every time. Is this possible?

Answers

  • Create a new txtfile, pase this content:

    @echo Set objShell = CreateObject("Shell.Application") > %temp%sudo.tmp.vbs
    @echo args = Right("%*", (Len("%*") - Len("%1"))) >> %temp%sudo.tmp.vbs
    @echo objShell.ShellExecute "%1", args, "", "runas" >> %temp%sudo.tmp.vbs
    @cscript %temp%sudo.tmp.vbs

    and save it as SUDO.cmd.

    Now copy the cmd to your system32 folder.

    When you now want to run a programm with admin rights type this:

    sudo cmd /k javaw.exe JAVA file

    Now accept the UAC prompt.

    Hope this helps.

    André


    «A programmer is just a tool which converts caffeine into code» CLIP- Stellvertreter http://www.winvistaside.de/

    • Proposed as answer by

      Tuesday, August 17, 2010 12:52 PM

    • Marked as answer by
      Leo Huang
      Wednesday, August 25, 2010 1:14 AM

  • Hi harriet, there is a DOS command you can use to run as administrator in command line:

    runas /profile /user:administrator “Driver:folderprogram”

    For example, the administrator account is “AAA” and you want to run BBB.exe of C:programs, you should do these following steps:

    1 Press Win key & R

    2 Input “CMD” in open box and click “OK”

    3 Input: runas /profile /user:AAA “C:programsBBB.exe”  and press “Enter”

    4 Input the password of administrator AAA

    5 Press “Enter”

    Hope it works.

    • Marked as answer by
      Leo Huang
      Wednesday, August 25, 2010 1:14 AM

This works for me on all platforms, including Windows 10. My needs are simple, perhaps you can adapt the approach if you need power.

I came up with a small script named, sudo.cmd named for the Linux sudo command. It works well enough it think. I’ve outlined the requirements, the steps to follow and the script is near the bottom with an example. First a word of warning.

WARNING:
The command runs in the windows System directory by default. You will want to cd to somewhere safe first.

requirements:

  • Run command with Administrator a privileged from windows .CMD
    or the cmd-shell.
  • require the normal Windows privilege checks on the command
    • In other words the command will NOT work unless I am already
      logged in with a privileged account.
  • Execute the command with Admin permission and continue when
    called inside a script. So wait for the command to complete.
  • Be simple so it will always work
  • Not need to enter a password every time, if I’m already logged in.
    • A better method would be if I can enter password once as does
      the real sudo command on Linux.

solution:

  1. Create a command script to execute all the arguments passed, sudo.cmd
  2. Create a Windows short-cut to the command script name it: sudo.lnk.
  3. Put the sudo short-cut in your windows PATH so it can be seen.
  4. Edit the short-cut properties, make the Start in: path empty.
  5. Click the [Advanced] button — Check Run as Administrator
  6. Enable short-cuts in your windows path, use the PATHEXT environment variable, viz.
d:> echo %PATHEXT%
    .lnk;.EXE;.CMD;.BAT;.COM

When you type sudo dir on the command-line Windows will show the

User Account Control

Do you want to allow this app to make changes to this device?

  [YES]  [NO]

Access control pop-up. If you click «[NO]» nothing will happen. Windows will show an «Access is denied.» message.

When you click «[YES]» then the directory command runs at an elevated privilege. Of course you probably want something more interesting like stopping or query on a service:

 sudo sc query SDRSVC

SDRSVC is the service name for «Windows Backup service», this shows the following in a separate Cmd window:

  [sudo]

   administrator
  ---------------

  sc query SDRSVC

SERVICE_NAME: SDRSVC
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 4  RUNNING
                                (STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0

  [done]

Press any key to continue . . .

The sudo.cmd script itself is very basic. As I said my needs are simple. I just want to stop and start services while I deploy code for testing.

sudo.cmd:

 @echo off
 @rem    sudo.cmd
         cd /d %temp%
 @echo.
 @echo.   administrator
 @echo.  ---------------
         cd 
 @echo.
 @rem  _________________________________________________
 @rem      -- Print usage . . .
        @if    [""]      ==["%~1"]   goto USAGE
        @if /i ["--HELP"]==["%~1"]   goto USAGE
 @rem  _________________________________________________
 @rem
 @echo.  %*
 @rem
         %*
 @rem
         set EXIT_STATUS=%ERRORLEVEL%
 @rem  -- -- -- -- --  
 @echo.
 @echo.  [done]
 @rem  ______________________________________________________
 :Exit
 @echo.
 @pause
  exit /b  %EXIT_STATUS%
 @rem  ______________________________________________________
 :USAGE
 @echo.
 @echo  ^Usage:
 @echo.    sudo ^<complete command line^>
 @echo.
 @echo.  Attempts to rune the: ^<complete command line^>
 @echo.  under Administrator priviliges.  Relies on Windows 
 @echo.  prompt for elevated privileges.
 @rem  ______________________________________________________
 @goto Exit

The pause command waits for you to review the results. If you take pause out the administration window closes and you don’t know if the command worked or not. The ERRORLEVEL from the command is returned as well.

Run as administrator on Windows 10
Run as administrator on Windows 10
(Image credit: Windows Central)

On Windows 10, the ability to run an app as administrator is an essential skill that every user should know because, by design, apps operate in user mode to prevent potential unwanted system changes that may negatively affect the experience. However, sometimes, some trusted programs may require elevated permissions to work as intended, and knowing the steps to run them with appropriate permissions will come in handy.

Whatever your reason it might be, Windows 10 includes several methods to quickly start an app with elevated privileges using the Start menu, File Explorer, Command Prompt, and more.

But remember that this is only true for traditional desktop (Win32) programs since apps available through the Microsoft Store can’t run elevated.

In this Windows 10 guide, we’ll walk you through the different ways to launch an app with administrator privileges to complete an elevated task.

  • How to run app as administrator using Stat menu
  • How to run app as administrator using Search
  • How to run app as administrator using desktop
  • How to run app as administrator using Run
  • How to run app as administrator using Task Manager
  • How to run app as administrator using File Explorer
  • How to run app as administrator using Command Prompt

Using the Start menu, you have at least two quick ways to start an application as an administrator.

To run a program as administrator from the Start menu context menu, use these steps:

  1. Open Start.
  2. Right-click the app (anywhere on the menu).
  3. Select the More submenu, and click the Run as administrator option.

Start menu context menu Run as administrator opion

Source: Windows Central (Image credit: Source: Windows Central)

To start an app with admin right using the keyboard shortcut, use these steps:

  1. Open Start.
  2. Use the Ctrl + Shift keyboard, and click the app from the list.
  3. (Optional) Select app using the arrows keys.
  4. Use the Ctrl + Shift + Enter keyboard shortcut.

How to run app as administrator using Search

If you use the search experience, you also have two ways to run apps with administrative permissions.

To open an app as an administrator from the search box, use these steps:

  1. Open Start.Quick tip: You can also open search directly from the taskbar (if available), or use the Windows key + S keyboard shortcut.
  2. Search for the app.
  3. Click the Run as administrator option from the right side. (Sometimes, the option is hidden until you click the down-arrow button.)

Search Run as administrator option

Source: Windows Central (Image credit: Source: Windows Central)
  1. (Optional) Right-click the app and select the Run as administrator option.

Search right-click Run as administrator option

Source: Windows Central (Image credit: Source: Windows Central)

Search keyboard shortcut

To run a program from search with a keyboard shortcut, use these steps:

  1. Open Start.
  2. Search for the app.
  3. Use the Ctrl + Shift + Enter keyboard shortcut.

How to run app as administrator using desktop

On Windows 10, you can also start apps elevated from the desktop or taskbar.

To start an app with elevated privileges from the desktop, use these steps:

  1. Use the Windows key + D keyboard shortcut to view the desktop.
  2. Right-click app, and select the Run as administrator option.

Windows 10 desktop run as administrator option

Source: Windows Central (Image credit: Source: Windows Central)

To run apps elevated from the taskbar, use these steps:

  1. Right-click the app in the taskbar.
  2. Right-click the app name.
  3. Select the Run as administrator option.

Windows 10 taskbar run as administrator option

Source: Windows Central (Image credit: Source: Windows Central)

How to run app as administrator using Run

To start a program as an admin user from the Run command, use these steps:

  1. Open Start.
  2. Search for Run and click the top result to open the app.Quick tip: You can also open the Run command using the Windows key + R keyboard shortcut.
  3. Type the name of the app. For example, explorer.exe.

Launch app as administrator with Run command

Source: Windows Central (Image credit: Source: Windows Central)
  1. Use the Ctrl + Shift keyboard shortcut and click the OK button.

How to run app as administrator using Task Manager

To launch an app as an administrator from Task Manager, use these steps:

  1. Open Start.
  2. Search for Task Manager and click the top result to open the app.Quick tip: Other alternative ways to open the experience include, right-clicking the taskbar and selecting the Task Manager option. Using the Ctrl + Shift + Esc keyboard shortcut, and using the Ctrl + Alt + Delete shortcut and clicking the Task Manager option.
  3. Click the File menu
  4. Select the Run new task option.

Task Manager run new task option

Source: Windows Central (Image credit: Source: Windows Central)
  1. Type the name of the app.
  2. Check the Create this task with administrator privileges.

Task Manager run as administrator option

Source: Windows Central (Image credit: Source: Windows Central)

How to run app as administrator using File Explorer

File Explorer includes at least two ways to launch apps as an administrator user.

To open app elevated with File Explorer, use these steps:

  1. Open File Explorer.
  2. Navigate to the folder with the executable file.
  3. Right-click the app and select the Run as administrator option.

File Explorer context menu options

Source: Windows Central (Image credit: Source: Windows Central)

To run a program as an administrator with the ribbon menu, use these steps:

  1. Open File Explorer.
  2. Navigate to the folder with the executable file.
  3. Select the app.
  4. Click the Application Tools tab.
  5. Click the Run as administrator button.Quick note: If you click the arrow button, then you can select to launch the app as admin or as a different user.

File Explorer ribbon menu run as administrator option

Source: Windows Central (Image credit: Source: Windows Central)

How to run app as administrator using Command Prompt

To run an app elevated from Command Prompt, use these steps:

  1. Open Start.
  2. Search for Command Prompt and click the top result to open the console.
  3. Type the following command to run an app with administrator privileges and press Enter:`runas /user:»COMPUTER-NAMEADMIN-USER» «C:PATHTOPROGRAM.EXE»In the command, make sure to update the syntax with your computer name and administrator user and with the correct path of the program.For example, this command start PowerShell 7 with administrator privileges:runas /user:"office-pcuser@email.com" "C:Program FilesPowerShell7pwsh.exe"

Command Prompt runas command

Source: Windows Central (Image credit: Source: Windows Central)
  1. Confirm the password and press Enter.

If you want to run an app always as an administrator, you can use these steps.

Get the best of Windows Central in in your inbox, every day!

Mauro Huculak is technical writer for WindowsCentral.com. His primary focus is to write comprehensive how-tos to help users get the most out of Windows 10 and its many related technologies. He has an IT background with professional certifications from Microsoft, Cisco, and CompTIA, and he’s a recognized member of the Microsoft MVP community.

Понравилась статья? Поделить с друзьями:
  • Windows run bat file at startup
  • Windows run app as admin without uac
  • Windows rt surface 64gb планшет характеристики
  • Windows rt surface 32 gb обновить до windows 10
  • Windows route add узнать номер интерфейса