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

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


当前回答

我想让这个上下文菜单只在右键单击并按住“SHIFT”时工作,这是内置的“在这里打开命令窗口”上下文菜单的工作方式。

然而,所提供的解决方案都没有做到这一点,所以我不得不滚动我自己的.reg文件-复制下面的文件,将其保存为power-shell-here-on-shift。Reg并双击它。

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\powershell]
@="Open PowerShell here"
"NoWorkingDirectory"=""
"Extended"=""

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

其他回答

只是添加一个反向的技巧,在PowerShell提示符下你可以这样做:

ii .

or

start .

在当前目录中打开Windows资源管理器窗口。

您可以从这里下载inf文件-介绍PowerShell提示在这里

尝试PowerShell PowerToy…它为Open PowerShell Here添加了一个上下文菜单项。

或者您可以创建一个快捷方式,打开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'"

上面的答案需要您每次都键入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进行导航