您的位置:首页 > 其它

How can I always run the command prompt as administrator?

2013-05-16 15:40 369 查看
To do this, paste the following into notepad and save it with a ".reg" extension:

[code]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:



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



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):
[code]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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐