windows添加powershell到右键菜单(注册表)
windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\Directory\shell\Open_PowerShell] @="Open PowerShell here" "Icon"="powershell.exe" [HKEY_CLASSES_ROOT\Directory\shell\Open_PowerShell\command] @="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'" [HKEY_CLASSES_ROOT\Directory\Background\shell\Open_PowerShell] @="Open PowerShell here" "Icon"="powershell.exe" [HKEY_CLASSES_ROOT\Directory\Background\shell\Open_PowerShell\command] @="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'" [HKEY_CLASSES_ROOT\Drive\shell\Open_PowerShell] @="Open PowerShell here" "Icon"="powershell.exe" [HKEY_CLASSES_ROOT\Drive\shell\Open_PowerShell\command] @="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'"
使用方法
将上述代码复制到文本编辑器(如记事本)中,保存为
Add_PowerShell_Here.reg(注意扩展名必须是.reg)。双击该文件,系统会询问是否确认将信息添加到注册表,选择“是”。
打开任意文件夹、在文件夹空白处右键或右键点击某个驱动器,即可看到“Open PowerShell here”选项。
自定义建议
修改菜单文字:将脚本中的
"Open PowerShell here"替换为其他文字,例如"在此处打开 PowerShell"。修改图标:可以将
"Icon"="powershell.exe"改为其他程序的路径或图标文件的路径。使用环境变量简化路径:如果希望命令更通用,可以将 PowerShell 路径简化为
"powershell.exe"(前提是 PowerShell 已加入系统 PATH)。修正文件夹右键菜单的命令:将
Directory\shell\Open_PowerShell\command中的%V改为%1,以确保功能正常:
@="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%1'"
同样,驱动器菜单也可改为 %1 保持一致性。