有没有办法从Windows资源管理器启动PowerShell在一个特定的文件夹,例如右键单击一个文件夹,并有一个选项,如“打开PowerShell在这个文件夹”?

每天我第一次运行MSBuild时,都要更改项目文件夹的目录,这真的很烦人。


当前回答

有一个Windows资源管理器扩展是由一个为SVN制作工具的家伙做的,它至少会打开一个命令提示窗口。

我还没有尝试过,所以我不知道它是否能做PowerShell,但我想与Stack Overflow的兄弟们分享我的爱:

http://tools.tortoisesvn.net/StExBar

其他回答

上面的答案需要您每次都键入PowerShell命令(PowerShell .exe),作为替代方法,您可以创建一个上下文菜单条目,就像“在这里打开命令窗口”上下文菜单一样。

这些命令有三个注册表项。每个键控制不同Windows资源管理器对象的上下文菜单。第一个是你问的问题:

HKCR\Directory\Background\shell -这是资源管理器窗口本身的上下文菜单(也就是说,当没有选择项目时显示的上下文菜单,例如在窗口的空白区域右击时)。 HKCR\Directory\shell -这是Windows资源管理器中文件夹的上下文菜单。 HKCR\Drive\shell -这是Windows资源管理器根目录中驱动器图标的上下文菜单。

对于每个注册表项,您可以添加一个子键,该子键将向上下文菜单添加一个“在此打开PowerShell窗口”命令,就像您有一个“在此打开命令窗口”上下文菜单一样。

这是我的OpenPowerShellHere的副本。reg文件,它把命令放在每个资源管理器对象、窗口背景、文件夹和驱动器图标的上下文菜单中:

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'"

因此,使用您喜欢的文本编辑器打开一个名为OpenPowerShellHere.reg的新文件。复制上面代码的确切文本,将其粘贴到新文件中,并保存。(我本想附上一份文件副本,但我不知道是否可以附上附件。)如果您想从一个条目中排除该命令,只需用分号注释掉相应的部分。我的注释向您展示了每个部分。

保存文件后,通过双击它来运行它。当它提出要求时,告诉它继续。只要您运行它,上下文菜单项就会显示出来!

这是资源管理器窗口上下文菜单。我突出显示了控制台和PowerShell命令。如您所见,您还可以添加一个上下文菜单条目来运行提升的命令窗口,即以管理员身份运行。

注意:上下文菜单项根据它们的注册表项按字母顺序显示。提升的命令shell的关键名称是“runas”,这就是为什么它出现在PowerShell条目之后。

注意:如果您打开了一个资源管理器窗口,您可能需要关闭它并重新打开它以使更改生效。

注意:在Windows 7中,如果使用资源管理器一侧的工具包,HKCR\Directory\Shell将无法工作

(即。点击Libraries标题下的Documents)

您必须使用Computer -> C: ->到-> Some -> Target -> Directory进行导航

在Windows资源管理器中,只需转到顶部的地址栏(键盘快捷键:Alt+D或Ctrl+L),输入powershell或powershell_ise并按Enter。将打开一个PowerShell命令窗口,其中包含当前目录。

只有在Windows 10上我才用得到……

创建一个名为PowershellHereContextMenu的文件。reg与下面的内容,右键单击它,并“合并”。

Windows Registry Editor Version 5.00

;
; Add context menu entry to Windows Explorer folders
;
[HKEY_CLASSES_ROOT\Directory\shell\powershellmenu]
@="PowerShell Here"

[HKEY_CLASSES_ROOT\Directory\shell\powershellmenu\command]
@="C:\\\\Windows\\\\system32\\\\WindowsPowerShell\\\\v1.0\\\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%L'"

;
; Add context menu entry to Windows Explorer background
;
[HKEY_CLASSES_ROOT\Directory\Background\shell\powershellmenu]
@="PowerShell Here"
"NoWorkingDirectory"=""

[HKEY_CLASSES_ROOT\Directory\Background\shell\powershellmenu\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\powershellmenu]
@="PowerShell Here"
"NoWorkingDirectory"=""

[HKEY_CLASSES_ROOT\Drive\shell\powershellmenu\command]
@="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'"

我创建了一个完全自动化的解决方案来添加PS和CMD上下文项。 只需运行set_registry。cmd,它将更新注册表添加两个按钮时,点击人民币的文件夹或在一些打开的文件夹:

这将更改注册表项的所有者为admin并添加上下文菜单 更改注册表以启用PS和CWD上下文菜单

我很惊讶没有人给出这个答案,这是最简单的答案。(一定是那年。)

只需在资源管理器中Shift +右键单击。然后你可以在这里打开PowerShell窗口。

默认情况下可以设置为命令提示符。如果是这样,你可以在Windows 10设置中进行更改:转到个性化->任务栏,启用“当我右键单击开始按钮或按Windows键+X时,将菜单中的命令提示符替换为Windows PowerShell”。