当前位置:首页 > 安全编程

windows添加powershell到右键菜单(注册表)

admin2小时前安全编程2
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'"

使用方法

  1. 将上述代码复制到文本编辑器(如记事本)中,保存为 Add_PowerShell_Here.reg(注意扩展名必须是 .reg)。

  2. 双击该文件,系统会询问是否确认将信息添加到注册表,选择“是”。

  3. 打开任意文件夹、在文件夹空白处右键或右键点击某个驱动器,即可看到“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 保持一致性。

相关文章

windows添加cmd到右键菜单(注册表)

在日常使用 Windows 时,我们经常需要在某个文件夹路径下快速打开命令提示符(CMD)并直接进入该目录。虽然 Windows 10/11 的资源管理器地址栏输入 cmd 也能实现,但很多用户更习惯…