Windows service run as administrator command line

How do you run a command as an administrator from the Windows command line?

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 the Windows shell (cmd.exe)—just as if I’d right-clicked it and chosen Run as Administrator, but without using any method that requires use of the graphical interface.

8 Answers 8

A batch/WSH hybrid is able to call ShellExecute to display the UAC elevation dialog.

Press the start button. In the search box type «cmd», then press Ctrl + Shift + Enter

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

In my case, this was

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:\Windows\System32 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 Policies\Security 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.

13 ways to use “Run as administrator” in Windows 10

In Windows 10, knowing how to run programs as administrator is very important. By default, apps and games in Windows 10 run without administrator permissions, to prevent unauthorized changes to your system. However, there are times when some programs require administrator permissions to work properly or to run specific commands. Windows 10 offers you the ability to run programs as admin without having to disable anything. Here are all the methods to use “Run as administrator” on any desktop app in Windows 10:

First things first: About UAC and Run as administrator

In early versions of Windows, applications had system-wide privileges, which was a security risk. All of Microsoft’s operating systems from Windows Vista onward, including Windows 10, include UAC or User Account Control, a security feature that prevents unauthorized changes to the operating system. Trying to run an application as administrator is one of the changes that require administrative privileges. Before the selected program is launched, a UAC prompt is triggered, asking for permission. If you run the application from an account without administrator permissions, the UAC prompt asks you to enter an administrator password. Without the admin password, the program does not launch.

Читайте также:  Update opengl version windows

In Windows 10, you can only run a program with administrator permissions if it is a desktop app. Some of these applications, like security software, cannot run correctly without having administrative permissions. Windows apps that are installed from the Microsoft Store cannot be run with administrative privileges in Windows 10. Furthermore, they have the same level of permissions as a normal user account, so they are not allowed to make changes to advanced system settings or the Windows Registry.

You can learn more about the difference between desktop apps and UWP apps and figure out which ones you can “Run as administrator” by reading What is a Windows app? How is it different from a desktop app or a program?.

1. Run a program as admin from the contextual menu of its Start Menu shortcut or tile

In Windows 10, you can launch a program with administrative permissions by using the contextual menu of its Start Menu shortcut. First, open the Start Menu. Then, find the shortcut of the program you want to launch in the All apps list, and right-click or press-and-hold on it to open a contextual menu. Click, tap, or hover over the More option, and then click or tap on “Run as administrator.

If you have a tile for your desktop app available in the Start Menu, right-click or press-and-hold on it to open a contextual menu. Access More and then click or tap on “Run as administrator.

2. Run as administrator using “Ctrl + Shift + Click” on its Start Menu shortcut or tile

Open the Start Menu and locate the shortcut of the program you want to launch as administrator. Hold down both the Ctrl and the Shift keys on your keyboard and then click or tap on that program’s shortcut.

You can also use the “Ctrl + Shift + Click/Tap” shortcut on an app’s Start Menu tile to run it with administrator permissions in Windows 10.

During our tests, this method did not work every time, so if that is the case for you, either try again or consider running the app as administrator another way.

3. Run a program as administrator from its desktop shortcut

Find the desktop shortcut for the program you want to run as admin or create one yourself. Then, right-click or press-and-hold on it to open a contextual menu. Click or tap on the “Run as administrator” option.

4. Run a desktop app as administrator from its taskbar shortcut

In Windows 10, you can also run a desktop app with administrator permissions from its taskbar shortcut. Right-click or press-and-hold on the shortcut, and then right-click or press-and-hold again on the program’s name. Then, from the menu that opens, choose “Run as administrator.”

You can also use the “Ctrl + Shift + Click/Tap” shortcut on an app’s taskbar shortcut to run it with administrator permissions in Windows 10.

5. Run a program as administrator from its right-click menu

Although easier to find, shortcuts are not the only way to run a program as administrator in Windows 10. You can perform the same action from the main executable file’s contextual menu.

Open File Explorer and find the desktop app’s executable. Right-click or press-and-hold on it to open the contextual menu, and then click or tap on “Run as administrator.

6. Use “Run as administrator” from File Explorer’s ribbon

Find the program’s main executable in File Explorer. Select it, and then click or tap on the Manage tab from the ribbon.

The option you need is displayed in the Run section of Application Tools. Click or tap on the upper half of the “Run as administrator” button to give the selected app admin permissions.

As an alternative, you can also press the lower half of the “Run as administrator” button and then click or tap on the “Run as administrator” option from the drop-down menu.

In the taskbar search field, type in the name of the program that needs to run with administrator permissions. Then, click or tap on the “Run as administrator” option displayed on the right side of the Search window.

Читайте также:  Easycap windows 10 не видит

Obviously, when you see the UAC prompt asking for permission to run the app as admin, click or tap Yes.

8. Run a program as administrator using “Ctrl + Shift + Enter” on its taskbar search result

Type the name of the program in your taskbar’s search field. If there are multiple results, use the arrow keys on your keyboard to highlight the program you want to run as administrator. Then, simultaneously press the Ctrl + Shift + Enter keys on your keyboard.

9. Run a program as administrator from the Run window

Open the Run window and type in the name of the executable for the program you want to run as administrator. Then hold down the Ctrl and Shift keys on your keyboard and click or tap on OK.

Alternatively, after typing in the name of the program’s main executable, press the Ctrl + Shift + Enter keys on your keyboard at the same time.

10. Run as admin from the Task Manager

Another way to launch a program as administrator in Windows 10 is to start it using the Task Manager. To begin, open the Task Manager. Then, if it opens up in its compact view, click or tap on the More details button.

In the expanded Task Manager, open the File menu and click or tap on “Run new task.

This opens the “Create new task” window. You can use its Open field to enter the path to the program you want to launch as administrator, or you can click or tap on Browse to navigate to it. Then, make sure to check the “Create this task with administrative privileges.” option and click or tap on OK.

TIP: An advantage of using this method to launch programs as administrator is that you skip the UAC part of the process. That is because the app automatically inherits the permissions of the Task Manager – in our case, administrator permissions – so all you have to do is check the box to enable the option, as seen above. The option is missing if you only have standard user permissions on the device.

11. Run a desktop app as admin using the RunAs command in Command Prompt (CMD) or PowerShell

If the command line is your favorite way of asking your computer to do what you want, you can also access Command Prompt or PowerShell to run a program as administrator. Enter the following command in the CMD or PowerShell window, adjusting it to fit your needs:

runas /user:”your_computer_name\administrator_name”C:\path\program.exe

Replace your_computer_name with your computer’s name, administrator_name with the name of a user account that is an administrator on your system, and C:\path\program.exe with the complete path to the program that you want to run as administrator.

As seen in the image below, if you enter the command correctly, you are also asked to enter the administrator’s password. Then, press Enter on your keyboard once again.

TIP: Using this method to launch programs as administrators, you skip the UAC part of the process.

12. Always run a program with administrator permissions

To avoid constantly having to use the methods illustrated above on desktop apps accessed on a regular basis, you can set a program to always run with administrator permissions.

First, open File Explorer and find the main executable of the program you want to run. Right-click or press and hold on it to open the contextual menu. Then, click or tap on Properties.

In the Properties window, go to the Compatibility tab. At the bottom of the window, check the box next to the “Run this program as an administrator” option, and then click or tap on Apply or OK.

This setting is applied, and, from now on, the program always runs with administrator permissions. Follow the same steps if you want to disable the option. You can also edit the Properties of a program’s shortcut to avoid tampering with its main executable. To begin, right-click or press-and-hold on a program’s shortcut to access its contextual menu, and click or tap on Properties.

Then, in the shortcut’s Properties window, select the Shortcut tab. Click or tap on the Advanced button to open Advanced Properties.

In the Advanced Properties window, check the box next to “Run as administrator” and then click or tap OK.

Finally, you are returned to the Properties window, where you have to click or tap on OK or Apply, and you are done.

Читайте также:  Что такое компьютеров mac os

The settings are applied, and your program works with administrative permissions as long as you open it using the same shortcut. When you use the methods in this section, the UAC prompts you as soon as you try to launch the app.

13. Run a program with administrator permissions and without a UAC prompt

Using the Task Scheduler, you can run a program as administrator without being prompted by the UAC (User Account Control) every time. It is simple, and you don’t have to disable UAC, thus compromising Windows 10’s security. We put together a detailed step by step guide to help you: Use the Windows Task Scheduler to run apps without UAC prompts and admin rights.

Which method(s) do you plan to use?

In Windows 10, there are fewer apps that need to run with administrator permissions than in older versions of Windows. However, a few legitimate programs still require elevated privileges. The main thing to remember is that even if you are logged in with an administrator account, you regularly run apps as a standard user. This means that if you need to run a program that requires administrator permissions, you can just use one of the methods described above and then approve it in the UAC prompt. Which of the method(s) illustrated do you plan to use? Did you already use some of them? Let us know in a comment.

How to Run Command Prompt as an Administrator in Windows 10

A small tip on how to run your command prompt as an administrator or in other words, open an elevated command prompt, in Windows 10/8/7. We have seen how to launch Command Prompt, and carry out many tasks. But some tasks required elevated privileges to be run. In such cases, you have to open an elevated command prompt window. So let us see how to launch, run or open Command Prompt as an administrator or an elevated CMD with administrative privileges & rights in Windows 10/8/7.

Run Command Prompt as Administrator

In Windows 10 and Windows 8, follow these steps:

Take the cursor to the bottom left corner and right-click to open the WinX menu. Select Command Prompt (Admin) to open an elevated command prompt.

So you see, things have been made easier in Windows 10/8.1.

In Windows 7, follow these steps:

Type cmd in Start search.

In the results, you will see ‘ cmd ‘.

Right-click on it and from the context menu select Run as Administrator.

TIP: This post will help you if you can’t run Command Prompt as administrator.

There are other ways to open an elevated command prompt:

  1. Press Ctrl+Shift+Esc to open the Task Manager. Click on File menu > Run new task. To open a command prompt window, type cmd. Remember to check the Create this task with administrative privileges check-box. Then hit Enter.
  2. You can also open an elevated Command Prompt from the Task Manager using CTRL key.
  3. Or then simply open the Start Menu or Start Screen and start typing the command line. Next, hold the Shift and Ctrl keys, and then hit Enter to open the command line in an elevated command prompt.
  4. Open an elevated command prompt using CMD
  5. Run Commands from Windows Start Search Box as an Administrator
  6. Run commands from Explorer address bar.

Best Cybersecurity Practices for Small Business

How to open .URL files with any Browser in Windows 10

You must have Read permissions to view the properties of this object

[email protected]

Anand Khanse is the Admin of TheWindowsClub.com, a 10-year Microsoft MVP (2006-16) & a Windows Insider MVP. Please read the entire post & the comments first, create a System Restore Point before making any changes to your system & be careful about any 3rd-party offers while installing freeware.

Primary Sidebar

report this ad

Оцените статью