如何从Windows资源管理器启动PowerShell?

如何从Windows资源管理器启动PowerShell?,windows,powershell,Windows,Powershell,是否有办法从Windows资源管理器在特定文件夹中启动PowerShell,例如在文件夹中单击鼠标右键,然后使用类似“在此文件夹中打开PowerShell”的选项 每天第一次运行MSBuild时,必须将目录更改到我的项目文件夹中,这真的很烦人。试试。。。它在此处为Open PowerShell添加上下文菜单项 或者,您可以创建一个快捷方式来打开PowerShell,其中“开始位置”文件夹是您的项目文件夹。您可以从此处下载inf文件-只需将其添加到相反的位置即可,在PowerShell提示下,您可

是否有办法从Windows资源管理器在特定文件夹中启动PowerShell,例如在文件夹中单击鼠标右键,然后使用类似“在此文件夹中打开PowerShell”的选项

每天第一次运行MSBuild时,必须将目录更改到我的项目文件夹中,这真的很烦人。

试试。。。它在此处为Open PowerShell添加上下文菜单项


或者,您可以创建一个快捷方式来打开PowerShell,其中“开始位置”文件夹是您的项目文件夹。

您可以从此处下载inf文件-

只需将其添加到相反的位置即可,在PowerShell提示下,您可以执行以下操作:

ii .


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

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

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


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

另一个选项是由Michael Murgolo在TechNet上制作的优秀提升PowerToys


它们包括此处的PowerShell提示符和此处的PowerShell管理员提示符。

如果您使用的是Windows 8或更高版本,只需使用内置文件即可→ “打开Windows PowerShell”


或者Alt+F后跟R.

一个相当简单的替代方法是通过快捷方式调用PowerShell。有一个标记为“起始位置”的快捷方式属性,说明调用快捷方式时要使用的目录(文件夹)

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

首次以常规方式创建PowerShell的快捷方式时,“开始位置”框指定主目录。如果您将“开始位置”框清空,则现在有一个到powershell的快捷方式,可以在当前目录中打开PS,不管是什么

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


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

在Windows 8.1和Server 2012 R2中,这更容易

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


然后,每当您需要PowerShell提示符时,点击Win+X,I.(或Win+X,a表示管理员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的新文件。复制上述代码的精确的文本,将其粘贴到新文件中,然后保存。(我本来会包含该文件的副本,但我无法确定是否可以使用附件。)如果要从其中一个条目中排除该命令,只需用分号注释掉相应的部分。我的注释会显示每个部分

保存文件后,双击它来运行它。当它请求时,告诉它继续。一旦运行它,上下文菜单条目就会显示出来

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

注意:上下文菜单项根据其注册表项按字母顺序显示。提升的命令shell的键名为“runas”,这就是它位于PowerShell项之后的原因

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

注意:在Windows 7中,如果使用浏览器一侧的工具包,
HKCR\Directory\Shell
将不起作用

(即,单击库标题下的文档)


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

只有在右键单击并按住SHIFT键时,才能使用此上下文菜单,这是内置的“在此处打开命令窗口”上下文菜单的工作方式

但是,所提供的解决方案都没有做到这一点,因此我必须滚动我自己的
.reg
文件-复制下面的内容,将其保存为shift.reg上的
power shell,然后双击它

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'"
通过添加r
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 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."
}
; 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
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'"