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

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


当前回答

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

其他回答

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

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

通过添加下面的注册表键,在Windows 10中,我成功地在我的SHIFT + RClick上下文菜单中获得了Open PowerShell Here选项。 只需将这些复制到一个空白的记事本文件中,然后保存为.reg文件,并运行该文件来添加密钥,它应该从那里开始工作。 其中一些其他答案说,将密钥添加到HKCR\Directory\shell,但我发现,对我来说,它只适用于进入HKLM\SOFTWARE\Classes\Directory\shell的密钥

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\powershell]
"Extended"=""
"NoWorkingDirectory"=""
@="Open PowerShell here"
"Icon"="%SystemRoot%\\system32\\WindowsPowerShell\\v1.0\\powershell.exe"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\powershell\command]
@="C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\powershell]
@="Open PowerShell here"
"Extended"=""
"Icon"="%SystemRoot%\\system32\\WindowsPowerShell\\v1.0\\powershell.exe"
"NoWorkingDirectory"=""

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

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

对于自动热键用户,这里有一个片段我正在使用

当按Ctrl-Alt-T时,它会打开PowerShell窗口。(Win10测试)

如果您的“活动窗口”是Windows资源管理器窗口,那么PowerShell将在当前文件夹中打开。否则,只需在某个默认文件夹中打开PowerShell。

使用方法:1)安装AutoHotkey,复制粘贴到myscript。2)将<DefaultPath>替换为您选择的路径。3)运行脚本。

; Ctrl-Alt-T opens PowerShell in the current folder, if using Windows Explorer. Otherwise, just open the Powershell.
^!T::
if WinActive("ahk_class CabinetWClass") and WinActive("ahk_exe explorer.exe")
{
    KeyWait Control
    KeyWait Alt
    Send {Ctrl down}l{Ctrl up}
    Send powershell{Enter}
}
else
{
    psScript =
    (
    cd 'C:\<DefaultPath>'
    ls
    )
    Run "%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe" -NoExit -Command &{%psScript%}
}
return

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

或者您可以创建一个快捷方式,打开PowerShell的开始文件夹是您的项目文件夹。