【发布时间】:2019-01-07 17:00:22
【问题描述】:
我创建了一个 Explorer Shell 级联上下文菜单,用于使用下面显示的代码在目录中打开 PowerShell。 (注意:我在管理命令中有一个硬编码的示例路径用于测试。)
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\powershell.exe]
"MUIVerb"=""
"SubCommands"="powershell;powershell_admin"
"Icon"="PowerShell.exe"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\powershell]
@="Open PowerShell here"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\powershell\command]
@="powershell.exe -NoLogo -NoExit -Command Set-Location '%V'"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\powershell_admin]
@="Open PowerShell (admin) here"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\powershell_admin\command]
@="powershell.exe -Command 'Start-Process PowerShell -ArgumentList \"-NoLogo -NoExit -Command Set-Location C:\Python27\" -Verb RunAs'"
非管理员命令完美运行。 admin 命令忽略 ArgumentList 中的所有内容。
如果我打开一个 PowerShell 并直接在单引号 (') 中执行代码,它就可以正常工作。例如:
Start-Process PowerShell -ArgumentList \"-NoLogo -NoExit -Command Set-Location C:\Python27\" -Verb RunAs
但是当从上下文菜单中执行时,它会以管理员模式打开,但会显示徽标并且不执行 Set-Location。
提前致谢
【问题讨论】:
-
@="powershell.exe -Command Start-Process PowerShell -ArgumentList '-NoLogo -NoExit -Command Set-Location C:\Python27' -Verb RunAs"应该可以工作。
标签: powershell registry windows-explorer