我知道按住 Shift 键并单击鼠标右键即可获得此选项,但我不想按住 Shift 键来查看此选项。
例如,当 Git 安装在 Windows 上时,我不必按 Shift + 右键单击即可看到“在此处打开 Git bash”,因为它也会在右键单击时显示。
检查注册表,我发现在HKEY_CLASSES_ROOT\Directory\shell\git_shell\command
默认值下"C:\Program Files\Git\git-bash.exe" "--cd=%1"
HKEY_CLASSES_ROOT\Directory\shell\Powershell\command
默认值下为: powershell.exe -noexit -command Set-Location '%V'
。
因此,我认为如果我将自定义位置下的默认条目设置HKEY_CLASSES_ROOT\Directory\shell\PowershellHere\command
为powershell.exe -noexit -command Set-Location '%1'
,我将在右键单击菜单中看到 PowerShell 选项,但它不起作用:(
我能做些什么?
答案1
在此处创建一个新的注册表项:
HKEY_CLASSES_ROOT\Directory\Background\shell\PowershellHere
(对于该(Default)
值,您可以将其留空或添加 &PowershellHere,然后可以使用右键单击,然后使用字母 p 作为热键。)
在此处创建另一个注册表项:
HKEY_CLASSES_ROOT\Directory\Background\shell\PowershellHere\command
赋予(Default)
字符串以下值:
powershell.exe -noexit -command Set-Location -literalPath '%V'
或者
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -command Set-Location -literalPath '%V'
或者,你可以在以下位置劫持现有密钥: HKEY_CLASSES_ROOT\Directory\Background\shell\Powershell
通过删除Extended
和NoWorkingDirectory
子项(但是您需要regedit
以管理权限开始。
答案2
在 Powershell 中运行此命令以添加上下文菜单
这种方法产生了一个右键单击上下文菜单,该菜单既可以在文件夹上使用,也可以在文件夹的背景上使用,以实现如下所示的菜单:
- 运行管理 Powershell 提示符
- 粘贴以下命令:
reg delete "HKEY_CLASSES_ROOT\Directory\shell\PowershellConsoleHere" /f
reg delete "HKEY_CLASSES_ROOT\Directory\Background\shell\PowershellConsoleHere" /f
reg delete "HKEY_CLASSES_ROOT\Directory\Background\ContextMenus\MenuPowerShell\shell\open" /f
reg delete "HKEY_CLASSES_ROOT\Directory\Background\ContextMenus\MenuPowerShell\shell\runas" /f
######## Add “Powershell Console Here” options to context menu
#### Right-Click Folder context menu
reg add "HKEY_CLASSES_ROOT\Directory\shell\PowershellConsoleHere" /v MUIVerb /t REG_SZ /d "Powershell" /f
reg add "HKEY_CLASSES_ROOT\Directory\shell\PowershellConsoleHere" /v Icon /t REG_SZ /d "powershell.exe" /f
reg add "HKEY_CLASSES_ROOT\Directory\shell\PowershellConsoleHere" /v ExtendedSubCommandsKey /t REG_SZ /d "Directory\Background\ContextMenus\MenuPowerShell" /f
#### Right-Click Background context menu
reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\PowershellConsoleHere" /v MUIVerb /t REG_SZ /d "Powershell" /f
reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\PowershellConsoleHere" /v Icon /t REG_SZ /d "powershell.exe" /f
reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\PowershellConsoleHere" /v ExtendedSubCommandsKey /t REG_SZ /d "Directory\Background\ContextMenus\MenuPowerShell" /f
### Create sub-context menu options
## Sub-context menu option: Console
reg add "HKEY_CLASSES_ROOT\Directory\Background\ContextMenus\MenuPowerShell\shell\open" /v MUIVerb /t REG_SZ /d "Console" /f
reg add "HKEY_CLASSES_ROOT\Directory\Background\ContextMenus\MenuPowerShell\shell\open" /v Icon /t REG_SZ /d "powershell.exe" /f
# Set default key value "(Default)"
reg add "HKEY_CLASSES_ROOT\Directory\Background\ContextMenus\MenuPowerShell\shell\open\command" /f /ve /d "powershell.exe -noexit -command Set-Location '%V'"
## Sub-context menu option: Elevated Console
reg add "HKEY_CLASSES_ROOT\Directory\Background\ContextMenus\MenuPowerShell\shell\runas" /v MUIVerb /t REG_SZ /d "Elevated Console" /f
reg add "HKEY_CLASSES_ROOT\Directory\Background\ContextMenus\MenuPowerShell\shell\runas" /v Icon /t REG_SZ /d "powershell.exe" /f
reg add "HKEY_CLASSES_ROOT\Directory\Background\ContextMenus\MenuPowerShell\shell\runas" /v HasLUAShield /t REG_SZ /d "" /f
# Set default key value "(Default)"
reg add "HKEY_CLASSES_ROOT\Directory\Background\ContextMenus\MenuPowerShell\shell\runas\command" /f /ve /d "powershell.exe -noexit -command Set-Location '%V'"
这是基于 MSDN 博客文章增强“在此处打开命令提示符”上下文菜单体验
答案3
这是我用来将 Powershell 命令添加到 Windows 10 中的背景菜单的 reg 文件;
Windows Registry Editor Version 5.00
;Add_Open_Powershell_to_Context_Menu.reg
;Right-Click Background only
[HKEY_CLASSES_ROOT\Directory\Background\shell\02MenuPowerShell]
"MUIVerb"="PowerShell Prompts"
"Icon"="powershell.exe"
"ExtendedSubCommandsKey"="Directory\\Background\\ContextMenus\\MenuPowerShell"
[HKEY_CLASSES_ROOT\Directory\Background\shell\02MenuPowerShell]
"MUIVerb"="PowerShell Prompts"
"Icon"="powershell.exe"
"ExtendedSubCommandsKey"="Directory\\Background\\ContextMenus\\MenuPowerShell"
[HKEY_CLASSES_ROOT\Directory\Background\ContextMenus\MenuPowerShell\shell\open]
"MUIVerb"="PowerShell"
"Icon"="powershell.exe"
[HKEY_CLASSES_ROOT\Directory\Background\ContextMenus\MenuPowerShell\shell\open\command]
@="powershell.exe -noexit -command Set-Location '%V'"
[HKEY_CLASSES_ROOT\Directory\Background\ContextMenus\MenuPowerShell\shell\runas]
"MUIVerb"="PowerShell Elevated"
"Icon"="powershell.exe"
"HasLUAShield"=""
[HKEY_CLASSES_ROOT\Directory\Background\ContextMenus\MenuPowerShell\shell\runas\command]
@="powershell.exe -noexit -command Set-Location '%V'"