簡體   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