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

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


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

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

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

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

ii .

or

start .

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

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

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

http://tools.tortoisesvn.net/StExBar

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

另一个选择是Michael Murgolo在TechNet网站http://technet.microsoft.com/en-us/magazine/2008.06.elevation.aspx上推出的Elevation PowerToys。

它们包括PowerShell提示符在这里和PowerShell提示符在这里作为管理员。

如果你使用的是Windows 8或更高版本,你可以简单地使用内置的文件→“打开Windows PowerShell”。

或者Alt + F + R。

一个相当简单的替代方法是通过快捷方式调用PowerShell。有一个标记为“Start in”的快捷方式属性,它表示在调用快捷方式时使用哪个目录(文件夹)。

如果“起始位置”框为空,则表示使用当前目录。

当您第一次以通常的方式创建PowerShell的快捷方式时,start in框指定了主目录。如果你清空start in框,你现在有一个powershell的快捷方式,在当前目录下打开PS,不管那是什么。

如果现在将该快捷方式复制到目标目录,并使用资源管理器调用它,那么将启动指向目标目录的PS。

这个问题已经有了一个公认的答案,但我提供了另一种方式。

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

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

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

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

我想让这个上下文菜单只在右键单击并按住“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'"

通过添加下面的注册表键,在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'"
New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT
if(-not (Test-Path -Path "HKCR:\Directory\shell\$KeyName"))
{
    Try
    {
        New-Item -itemType String "HKCR:\Directory\shell\$KeyName" -value "Open PowerShell in this Folder" -ErrorAction Stop
        New-Item -itemType String "HKCR:\Directory\shell\$KeyName\command" -value "$env:SystemRoot\system32\WindowsPowerShell\v1.0\powershell.exe -noexit -command Set-Location '%V'" -ErrorAction Stop
        Write-Host "Successfully!"
     }
     Catch
     {
         Write-Error $_.Exception.Message
     }
}
else
{
    Write-Warning "The specified key name already exists. Type another name and try again."
}

您可以从Windows资源管理器中下载如何启动PowerShell的详细脚本

在最新版本的Windows 10中,当你用鼠标Shift+右键点击空白区域时,默认在上下文菜单中有“在此打开PowerShell窗口”,现在你应该已经在使用Windows终端了。

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

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

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

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

当按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

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

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

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

Windows 10让这一切变得简单多了。你可以:

SHIFT +鼠标右键单击一个文件夹,你会得到一个菜单项打开PowerShell窗口。

或者你可以:

File ->打开Windows PowerShell。

作为奖励…

如果您鼠标右键单击文件>打开Windows PowerShell,那么您可以添加到快速访问工具栏:

这里有一个方便的图标:

现在你可以点击那个图标。:)

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

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

只有在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,请到该文件夹,并使用快捷方式“alt + f + s + a”以管理员身份在该特定文件夹位置打开PowerShell

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

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