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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/183901/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 05:30:19  来源:igfitidea点击:

How do I start PowerShell from Windows Explorer?

windowspowershell

提问by Josh Kodroff

Is there a way to start PowerShell in a specific folder from Windows Explorer, e.g. to right-click in a folder and have an option like "Open PowerShell in this Folder"?

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

It's really annoying to have to change directories to my project folder the first time I run MSBuild every day.

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

回答by Ashwin Nanjappa

In Windows Explorer, just go to the Address Bar at the top (keyboard shortcuts: Alt+Dor Ctrl+L) and type powershellor powershell_iseand press Enter. A PowerShell command window opens with the current directory.

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

回答by EBGreen

Just to add in the reverse as a trick, at a PowerShell prompt you can do:

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

ii .

or

或者

start .

to open a Windows Explorer window in your current directory.

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

回答by Vivek Maharajh

If you're on Windows 8, or later, you can simply use the built-in File→ "Open Windows PowerShell".

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

Or Alt+ Ffollowed by R.

Alt+F后跟R.

回答by Chris Sutton

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

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

Scott Hanselman has a really simple inf that will do this for you. If you want to tweak the script it is really easy to go and edit the inf for customizations.

Scott Hanselman 有一个非常简单的 inf 可以为您做到这一点。如果您想调整脚本,那么编辑 inf 以进行自定义非常容易。

回答by geo

As an alternative to the answer above, which requires you to type the PowerShell command (powershell.exe) each time, you can create a context menu entry just like with the "Open command window here" context menu.

作为上述答案的替代方案,它要求您每次都键入 PowerShell 命令 ( powershell.exe),您可以创建一个上下文菜单条目,就像使用“在此处打开命令窗口”上下文菜单一样。

There are three registry keys where these commands go. Each key controls the context menu of a different Windows Explorer object. The first one is the one you asked about:

这些命令存在三个注册表项。每个键控制不同 Windows 资源管理器对象的上下文菜单。第一个是你问的那个:

  • HKCR\Directory\Background\shell- This is the context menu for the Explorer window itself (that is, the context menu that is displayed when no item is selected, such as when right-clicking in an empty area of the window).
  • HKCR\Directory\shell- This is the context menu of the folders in Windows Explorer.
  • HKCR\Drive\shell- This is the context menu for the drive icons in the root of Windows Explorer.
  • HKCR\Directory\Background\shell- 这是资源管理器窗口本身的上下文菜单(即当没有选择任何项目时显示的上下文菜单,例如在窗口的空白区域中右键单击时)。
  • HKCR\Directory\shell- 这是 Windows 资源管理器中文件夹的上下文菜单。
  • HKCR\Drive\shell- 这是 Windows 资源管理器根目录中驱动器图标的上下文菜单。

For each of these registry keys, you can add a subkey that will add an "Open PowerShell window here" command to the context menu, just as you have an "Open command window here" context menu.

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

Here is a copy of my OpenPowerShellHere.regfile, which puts the command in the context menu of each of the Explorer objects, the window background, the folder, and the drive icon:

这是我的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'"

So, with your favorite text editor, open a new file named OpenPowerShellHere.reg. Copy the exacttext of the code above, paste it into the new file, and save it. (I would have included a copy of the file, but I couldn't figure out if attachments were possible.) If you want to excludethe command from one of the entry, just comment out the appropriate section with semicolons. My comments show you each section.

因此,使用您最喜欢的文本编辑器,打开一个名为OpenPowerShellHere.reg的新文件。复制上面代码的确切文本,将其粘贴到新文件中,然后保存。(我会包含该文件的副本,但我无法确定是否可以添加附件。)如果您想从其中一个条目中排除该命令,只需用分号注释掉相应的部分即可。我的评论向您展示了每个部分。

After you save the file, run it by double-clicking on it. When it asks, tell it to proceed. As soon as you run it, the context menu entries will show up!

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

Here is my Explorer window context menu. I've highlighted the console and PowerShell commands. As you can see, you can also add a context menu entry to run an elevated command window, i.e., Run as Administrator.

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

PowerShell entry in Explorer context menu

资源管理器上下文菜单中的 PowerShell 条目

Note: Context menu entries are displayed alphabetically, based on their Registry keys. The key name for the elevated command shell is "runas", which is why it comes after the PowerShell entry.

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

Note: If you have an explorer window open, you may need to close it and reopen it to get the changed to take effect.

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

Note: In Windows 7, the HKCR\Directory\Shelldoes not work if you use the toolkit on the side of the explorer

注意:在 Windows 7 中,HKCR\Directory\Shell如果您使用资源管理器侧面的工具包,则不起作用

(ie. Clicking Documents under the Libraries header)

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

you must navigate using Computer -> C: -> to -> Some -> Target -> Directory

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

回答by Gulzar Nazim

You can download the inf file from here - Introducing PowerShell Prompt Here

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

回答by Default

In Windows 10 both the command prompt and the powershell prompt can be found via the menu bar, for both non-admin and admin. These options will have its folder set to the currently selected folder from the explorer.

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

For the Swedish version at least, the powershell is opened with AltF+I. For an administrator powershell it's AltF+S+P.

至少对于瑞典版本,powershell 是用AltF+I. 对于管理员 powershell,它是AltF+S+P.

Windows Powershell menu

Windows Powershell 菜单

If those are not the correct characters you can press and hold the Altkey to see the correct characters. there will be a character overlaying the menu item for each step.

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

回答by Daniel Sokolowski

I wanted to have this context menu work only when right clickingand holdingthe 'SHIFT' which is how the built in 'Open Command window here' context menu works.

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

However none of the provided solutions did that so I had to roll my own .regfile - copy the below, save it as power-shell-here-on-shift.regand double click on it.

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

按住 shift 并按右键单击此处打开电源外壳

回答by Steven Murawski

Try the PowerShell PowerToy... It adds a context menu item for Open PowerShell Here.

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

Or you could create a shortcut that opens PowerShell with the Start In folder being your Projects folder.

或者,您可以创建一个打开 PowerShell 的快捷方式,其中 Start In 文件夹是您的 Projects 文件夹。

回答by Josh Kodroff

There's a Windows Explorer extension made by the dude who makes tools for SVN that will at least open a command prompt window.

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

I haven't tried it yet, so I don't know if it'll do PowerShell, but I wanted to share the love with my Stack Overflow brethren:

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

http://tools.tortoisesvn.net/StExBar

http://tools.tortoisesvn.net/StExBar