How can I always run the command prompt as administrator?

To do this, 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 of any folder.

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:

How can I always run the command prompt as administrator?_第1张图片

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

How can I always run the command prompt as administrator?_第2张图片

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, technicallychange-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.

Referenced from: http://superuser.com/questions/453409/how-can-i-always-run-the-command-prompt-as-administrator


你可能感兴趣的:(How can I always run the command prompt as administrator?)