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:

enter image description here

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

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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值