繁体   English   中英

如何在Windows中创建上下文菜单条目以使用管理员权限打开PowerShell?

[英]How to create a context menu entry, in windows, to open PowerShell with administrator privileges?

有一个很棒的社区维基评论 ,演示了添加上下文菜单条目(但没有管理员权限)。 如何更改注册表项或以下.reg文件以使用管理员权限打开PowerShell?

Windows Registry Editor Version 5.00

;
; Add context menu entry to Windows Explorer background
;
[HKEY_CLASSES_ROOT\Directory\Background\shell\powershell]
@="Open PowerShell window here"
"NoWorkingDirectory"=""

[HKEY_CLASSES_ROOT\Directory\Background\shell\powershell\command]
@="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'"

;
; Add context menu entry to Windows Explorer folders
;
[HKEY_CLASSES_ROOT\Directory\shell\powershell]
@="Open PowerShell window here"
"NoWorkingDirectory"=""

[HKEY_CLASSES_ROOT\Directory\shell\powershell\command]
@="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'"

;
; Add context menu entry to Windows Explorer drive icons
;
[HKEY_CLASSES_ROOT\Drive\shell\powershell]
@="Open PowerShell window here"
"NoWorkingDirectory"=""

[HKEY_CLASSES_ROOT\Drive\shell\powershell\command]
@="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'"

解决方法:

通过向位于以下位置的注册表项添加条目,强制PowerShell每次都以管理员身份打开:

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers\

键名=路径 - 示例:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

价值数据:

RUNASADMIN



这不是我想要的方式,但它适用于我的目的。

使用密钥runas会导致任何命令以管理员身份运行。 下面你可以看到我使用的部分注册表调整,或者你可以在我的GitHub Gist上看到我使用的完整.reg文件

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\runas]
@="Open elevated PowerShell here"
"Extended"=""
"Icon"="powershell.exe"
"NoWorkingDirectory"=""

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\runas\command]
@="C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\runas]
"Extended"=""
"NoWorkingDirectory"=""
@="Open elevated PowerShell here"
"Icon"="powershell.exe"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\runas\command]
@="C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM