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

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


当前回答

通过添加下面的注册表键,在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'"

其他回答

通过添加下面的注册表键,在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'"

在Windows 10中,命令提示符和powershell提示符都可以通过菜单栏找到,无论是非管理员用户还是管理员用户。这些选项将其文件夹设置为当前从资源管理器中选择的文件夹。

至少对于瑞典版本,powershell是用Alt F+I打开的。对于管理员powershell,它是Alt F+S+P。

如果这些不是正确的字符,您可以按住Alt键查看正确的字符。每个步骤的菜单项上将覆盖一个字符。

您可以在Windows资源管理器地址栏上执行以下命令打开powershell,它将打开该目录的路径。

powershell.exe -noexit -command "Write-Host "Hello World"

只有在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'"

在Windows 8.1和Server 2012 R2中更容易。

这样做一次: 右键单击任务栏,选择“属性”。在导航选项卡中,当我右键单击左下角或按Windows键+X时,打开菜单中的[✓]将命令提示符替换为Windows PowerShell。

然后当你想要PowerShell提示时,点击Win+X, i(或Win+X, a表示Admin PowerShell提示)