首页 文章

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

提问于
浏览
232

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

在我第一次每天运行MSBuild时必须将目录更改为我的项目文件夹真的很烦人 .

17 回答

  • 40

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

  • 1

    只需添加反向作为技巧,在PowerShell提示符下,您可以执行以下操作:

    ii .
    

    要么

    start .
    

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

  • 5

    如果您使用的是Windows 8或更高版本,则可以使用内置文件→"Open Windows PowerShell" .

    或Alt F后跟R.

  • 12

    http://www.hanselman.com/blog/IntroducingPowerShellPromptHere.aspx

    Scott Hanselman有一个非常简单的inf,它会为你做这件事 . 如果你想调整脚本,很容易去编辑inf进行自定义 .

  • 1

    作为上述答案的替代方法,每次都需要您键入PowerShell命令(powershell.exe),您可以创建一个上下文菜单条目,就像使用“ Open command window here ”上下文菜单一样 .

    这些命令有三个注册表项 . 每个键控制不同Windows资源管理器对象的上下文菜单 . 第一个是您询问的问题:

    • HKCR\Directory\Background\shell - 这是资源管理器窗口本身的上下文菜单(即,未选择任何项目时显示的上下文菜单,例如右键单击窗口的空白区域时) .

    • HKCR\Directory\shell - 这是Windows资源管理器中文件夹的上下文菜单 .

    • HKCR\Drive\shell - 这是Windows资源管理器根目录中驱动器图标的上下文菜单 .

    对于每个这些注册表项,您可以添加一个子项,该子项将“在此处打开PowerShell窗口”命令添加到上下文菜单中,就像您在此处“打开命令窗口”上下文菜单一样 .

    这是我的 OpenPowerShellHere.reg 文件的副本,它将命令放在每个Explorer对象的上下文菜单中,窗口背景,文件夹和驱动器图标:

    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 的新文件 . 复制上面代码的 exact 文本,将其粘贴到新文件中,然后保存 . (我会包含该文件的副本,但我无法确定附件是否可行 . )如果要从其中一个条目中排除命令,只需用分号注释掉相应的部分 . 我的评论向您展示了每个部分 .

    保存文件后,双击它来运行它 . 当它询问时,告诉它继续 . 一旦运行它,上下文菜单条目就会出现!

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

    PowerShell entry in Explorer context menu

    Note :上下文菜单条目根据其注册表项按字母顺序显示 . 提升的命令shell的密钥名称是“runas”,这就是它在PowerShell条目之后出现的原因 .

  • 2

    你可以从这里下载inf文件 - Introducing PowerShell Prompt Here

  • 55

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

    至少对于瑞典语版本,使用Alt F I打开powershell . 对于管理员来说,它是Alt F S P.

    Windows Powershell menu

    如果这些字符不正确,您可以按住Alt键查看正确的字符 . 每个步骤都会有一个覆盖菜单项的字符 .

  • 4

    我希望只有在右键单击 holding 'SHIFT'时才能使用此上下文菜单,这是内置'Open Command window here'上下文菜单的工作方式 .

    但是,所提供的解决方案都没有这样做,所以我不得不滚动自己的 .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'"
    

    open power shell here while holding shift and pressing right click

  • 32

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

    执行一次:右键单击任务栏,选择“属性” . 在“导航”选项卡中,启用 [✓] Replace Command Prompt with Windows PowerShell in the menu when I right-click the lower-left corner or press Windows key+X .

    然后,无论何时需要PowerShell提示,请按Win X,I . (或者Win X,A用于Admin PowerShell提示)

  • 1

    试试PowerShell PowerToy ...它为Open PowerShell添加了一个上下文菜单项这里 .

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

  • 480

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

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

    http://tools.tortoisesvn.net/StExBar

  • 99

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

    它们包括PowerShell Prompt Here和PowerShell Prompt Here以管理员身份 .

  • 64

    以下是早期解决方案的简明(和更新)总结 . 这是做什么的:

    添加这些字符串及其各自的父键:

    pwrshell\(Default) < Open PowerShell Here
    pwrshell\command\(Default) < powershell -NoExit -Command Set-Location -LiteralPath '%V'
    pwrshelladmin\(Default) < Open PowerShell (Admin)
    pwrshelladmin\command\(Default) < powershell -Command Start-Process -verb runAs -ArgumentList '-NoExit','cd','%V' powershell
    

    在这些地方

    HKCR\Directory\shell (for folders)
    HKCR\Directory\Background\shell (Explorer window)
    HKCR\Drive\shell (for root drives)
    

    而已 . 如果您按住“Shift”键,则只为命令添加“扩展”字符串才能显示,其他一切都是多余的 .

  • 4

    通过添加下面的注册表项,在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'"
    
  • 3
    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."
    }
    

    您可以从how to start PowerShell from Windows Explorer下载详细脚本

  • 1

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

    如果“开始时间”框为空,则表示使用当前目录 .

    首次以常规方式创建PowerShell快捷方式时,“开始”框指定主目录 . 如果你在开始框中删空,你现在有了一个PowerShell的快捷方式,可以打开当前目录中的PS,无论是什么 .

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

    已经接受了这个问题的答案,但我提供了另一种方式 .

  • 2

    对于autohotkey用户来说,这是我正在使用的片段

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

    如果您的"active window"是Windows资源管理器窗口,则会在当前文件夹中打开PowerShell . 否则,只需在某个默认文件夹中打开PowerShell .

    用法:1)安装AutoHotkey,并将其粘贴到myscript.ahk中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
    

相关问题