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

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

当我第一次每天运行MSBuild时,不得不将目录切换到我的项目文件夹,这实在令人讨厌。

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

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

 ii . 

要么

 start . 

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

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

斯科特Hanselman有一个非常简单的inf,将为你做这个。 如果你想调整脚本,那么去编辑inf来进行自定义是很容易的。

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

或者Alt + F,然后是R。

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

有三个这些命令去的registry项。 每个键控制不同的Windows资源pipe理器对象的上下文菜单。 第一个是你问到的那个:

  • HKCR \ Directory \ Background \ shell – 这是资源pipe理器窗口本身的上下文菜单(即没有select项目时显示的上下文菜单,例如右键单击窗口的空白区域时)。
  • HKCR \ Directory \ shell – 这是Windows资源pipe理器中文件夹的上下文菜单。
  • HKCR \ Drive \ shell – 这是Windows资源pipe理器根目录中驱动器图标的上下文菜单。

对于这些registry项中的每一个,您都可以添加一个子项,以便在上下文菜单中添加“打开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的新文件。 复制上面代码的确切文本,将其粘贴到新文件中,然后保存。 (我会包含一个文件的副本,但是我不知道附件是否可能。)如果你想从一个条目中排除命令,只需用分号注释掉相应的部分。 我的评论显示你的每一节。

保存文件后,双击运行它。 当它询问时,告诉它继续。 只要你运行它,上下文菜单条目将显示!

这是我的浏览器窗口上下文菜单。 我已经突出了控制台和PowerShell命令。 正如你所看到的,你也可以添加一个上下文菜单项来运行一个提升的命令窗口,即以pipe理员身份运行

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

注意 :上下文菜单条目根据其registry项按字母顺序显示。 提升命令shell的键名称是“ runas ”,这就是为什么它在PowerShell条目之后。

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

在Windows 10中,命令提示符和PowerShell提示可以通过菜单栏find,非pipe理员和pipe理员。 这些选项将其文件夹设置为资源pipe理器中当前选定的文件夹。

至less在瑞典版本中,powershell是用Alt + F打开的。 对于pipe理员powershell它是Alt F + S + P。

Windows Powershell菜单

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

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

做一次:右键单击任务栏,select属性。 在“导航”选项卡中, 右键单击左下angular或按Windows键+ X ,打开[✓]用菜单中的Windows PowerShellreplace命令提示符

然后,只要你想要一个PowerShell提示符,打Win + X 。 (或Win + X ,pipe理PowerShell提示A

我只想右键点击按住 'SHIFT'这个'Open Command window here'上下文菜单是如何工作的。

然而,没有提供的解决scheme,所以我不得不推出我自己的.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'" 

在按住Shift键的同时按住右键打开电源外壳

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

或者,您可以创build一个打开PowerShell的快捷方式,将Start In文件夹作为您的Projects文件夹。

有一个Windows资源pipe理器的扩展名是由SVN制作的工具,至less会打开一个命令提示符窗口。

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

http://tools.tortoisesvn.net/StExBar

TechNet上Michael Murgolo提供的另一个选项是卓越的Elevation PowerToys,url为http://technet.microsoft.com/zh-cn/magazine/2008.06.elevation.aspx

它们包括PowerShell Prompt Here和PowerShell以pipe理员身份提示。

以下是对早期解决scheme的简要总结(和更新)。 这是做什么:

添加这些string及其各自的父键:

 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”键的情况下,才能为命令添加“扩展”string,否则其他部分都是多余的。

通过添加下面的registry项,在Windows 10中,我设法在我的SHIFT + RClick上下文菜单中获得了“ 打开PowerShell在这里”选项。 只需将这些文件复制到一个空白的记事本文件,然后保存为一个.reg文件并运行该文件添encryption钥,它应该从那里工作。 其中一些答案说,将密钥添加到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资源pipe理器启动PowerShell下载详细脚本

一个相当简单的select是通过快捷方式调用PowerShell。 有一个标有“Start in”的快捷方式属性,指出调用快捷方式时要使用的目录(文件夹)。

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

当您第一次以常规方式创buildPowerShell快捷方式时,“开始”框指定主目录。 如果你在开始框中填空,你现在有一个PowerShell的快捷方式,打开当前目录中的PS,不pipe是什么。

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

对这个问题已经有了一个可以接受的答案,但是我以另一种方式提出这个问题。

对于autohotkey用户,inheritance人我正在使用一个片段

当按下Ctrl-Alt-T时,它会打开PowerShell窗口。 (用Win10testing)

如果您的“活动窗口”是Windows资源pipe理器窗口,那么PowerShell将在当前文件夹中打开。 否则,只需在某个默认文件夹中打开PowerShell。

用法:1)安装AutoHotkey,并将其粘贴到myscript.ahk中2)将<DefaultPath>replace为您select的path。 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