Tell me more ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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)?

share|improve this question
Why not just change UAC to elevate only? – surfasb Jul 26 '12 at 2:46
I don't see an "elevate only" option on my UAC slider. Are you referring to something besides the User Account Control Settings window? – Kevin Jul 26 '12 at 11:37

5 Answers

up vote 24 down vote accepted

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.)

share|improve this answer
3  
Note; you will still have to accept the UAC prompt in both cases. – Synetech Jul 25 '12 at 17:17

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

The Compatibility tab is completely disabled for all of Windows’ executables:

enter image description here

To set admin privileges for Windows executables, you need to create a shortcut and use Shortcut tab→Advanced (the command-prompt item in the Start menu is already a shortcut):

enter image description here

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.

That is normal and makes sense since if you are opening an admin command-prompt, you are probably doing some system actions for which you need admin privileges instead of user actions that you already have permissions for anyway.

You can set the default directory globally by adding/editing the Autorun registry entry (it does not even have to be an expandable string to use environment variables):

REGEDIT4
[HKEY_CURRENT_USER\Software\Microsoft\Command Processor]
"Autorun"="cd /d \"%userprofile%\""

Now, any time you open a command-prompt using any method will automatically default (well, technically change-directory) to your user-profile directory.

Even better, you can add other commands to be automatically run whenever you open a command-prompt using the & operator (e.g., cd /d %userprofile% & cls & dir). In addition, you can set the same value in the same key under the HKLM branch to set it for all users.


Note that you will still have to accept the UAC prompt. Unfortunately there is (currently?) no way to create a UAC “whitelist” of trusted programs so that the command-prompt can be run as admin without having to accept the prompt. This leaves you with (a) few options.

  • You can turn UAC down or off altogether (useraccountcontrolsettings.exe)
  • You can use a privilege-elevation program like Elevator aka Elevate Me or the Elevation PowerToy
  • Create an elevated scheduled task, enter the credentials (once) for it, and then create a shortcut to the task

In the first case, you avoid the UAC altogether while in the latter two, you only enter your credentials once when creating the shortcut.

share|improve this answer

There have been a couple tools that I've used that were other workarounds (in addition to what Jesse mentioned).

Back when Vista first came out, Microsoft came out with an "elevate" powerToy that was quite useful and did the job and still, I believe (haven't tested) works for Windows 7. Drop it into your path environment and you could run "elevate iisreset" from a normal command prompt (or even "elevate cmd" from the start/run or a create a shortcut)

share|improve this answer

Create a shortcut to cmd.exe, right click and select properties, on the Shortcut tab select Advanced, check Run as Administrator.

share|improve this answer

To auto run CMD as admin each time it is simply clicked (without having to right-click or create additional shortcuts), there is an easy fix for this:

In the registry editor, navigate to "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" (If there isn't a Layers folder, you'll have to create one) For the value, make it the full path to command prompt. (i.e. C:\Windows\System32\cmd.exe and without quotes) and the data of that value "RUNASADMIN" without quotes.

I had this same annoyance, and it worked for me.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.