Windows – How to always run the command prompt as administrator

command linepermissionswindows 7

As a developer, I often have the need to open a command prompt for various purposes. For example, I use iisreset to restart my local web server.

I typically open the command window in one of two ways:

  1. Press Win, type "cmd" and press Enter
  2. While in Explorer, hold Shift and right click on a folder, and choose "Open command window here"

However, when I open the command window in either of these ways, I do not have the full administrator privileges that I feel I am entitled to.

I am an administrator, but cmd.exe doesn't know that

In order to run administrator-only applications, I have to open the command line in this relatively laborious way:

  1. Press Win, type "cmd"
  2. Wait for the menu to populate
  3. Lift hand off the keyboard and put it on the mouse
  4. Right click the "cmd.exe" menu item
  5. Choose "Run as administrator"

This is unacceptable for several reasons:

  • The window always opens in C:\windows\system32, rather than my Users directory (as in approved technique 1) or the folder I want to be in (as in approved technique 2). So I often have to change directories to get where I want to go.
  • This process is several milliseconds slower than either of my preferred methods. Performed several times a day, every day for the remainder of my career, it adds up to about ten days of lost time spent clicking and waiting and directory changing.
  • As a programmer, performing a pointless robotic task causes me great emotional pain.
  • As a programmer, lifting my hand is a strenuous task that causes me great physical pain.

That is why I am looking for a one-and-done solution that will let approved techniques 1 & 2 open administrator command prompts.

Many programs let you permanently change their default privilege level from the Properties menu. Command Prompt is not one of those programs.

enter image description here

How do I make the command window run as administrator by default (even when using the "Open command window here" context menu option)?

Best Answer

To answer the first part of your question, when you hit the Windows key and type "CMD" you can hit Ctrl + Shift + Enter to open as administrator.

To answer the second part of your question, paste the following into notepad and save it with a ".reg" extension:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\runas]
@="Open Command Window Here as Administrator"

[HKEY_CLASSES_ROOT\Directory\shell\runas\command]
@="cmd.exe /s /k pushd \"%V\""

Then run the file. It will merge the changes into the registry and add the option to your context menus. (No shift key needed.)