有没有办法从 Windows 资源管理器在特定文件夹中启动 PowerShell,例如右键单击文件夹并具有“在此文件夹中打开 PowerShell”之类的选项?
每天第一次运行 MSBuild 时,必须将目录更改为我的项目文件夹,这真的很烦人。
在 Windows 资源管理器中,只需转到顶部的地址栏(键盘快捷键:Alt+D 或 Ctrl+L kbd>) 并输入 powershell
或 powershell_ise
并按 Enter。 PowerShell 命令窗口将打开当前目录。
只是作为一个技巧反向添加,在 PowerShell 提示符下,您可以执行以下操作:
ii .
或者
start .
在当前目录中打开 Windows 资源管理器窗口。
ii
是什么意思?
code .
还会在当前文件夹中打开 Visual Studio Code - 这非常方便。
如果您使用的是 Windows 8 或更高版本,则可以简单地使用内置文件 → “打开 Windows PowerShell”。
或 Alt + F 后跟 R。
作为上述答案的替代方法,它要求您每次都键入 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 命令。如您所见,您还可以添加上下文菜单项来运行提升的命令窗口,即以管理员身份运行。
https://i.stack.imgur.com/aAR1T.png
注意:上下文菜单条目根据其注册表项按字母顺序显示。提升的命令外壳的键名称是“runas”,这就是它出现在 PowerShell 条目之后的原因。
注意:如果您打开了资源管理器窗口,您可能需要将其关闭并重新打开以使更改生效。
注意:在 Windows 7 中,如果您使用资源管理器一侧的工具包,HKCR\Directory\Shell
将不起作用
(即单击库标题下的文档)
您必须使用 Computer -> C: -> to -> Some -> Target -> Directory
导航
git help <cmd>
时,它会将 PS 窗口中的 html 帮助文件作为纯文本转储。当我使用开始菜单时,该 PS 窗口会按预期打开浏览器。
在 Windows 10 中,非管理员和管理员都可以通过菜单栏找到命令提示符和 powershell 提示符。这些选项会将其文件夹设置为资源管理器中当前选择的文件夹。
至少对于瑞典语版本,powershell 是用 Alt F+I 打开的。对于管理员 powershell,它是 Alt F+S+P。
https://i.stack.imgur.com/Ac8S8.png
如果这些不是正确的字符,您可以按住 Alt 键查看正确的字符。每个步骤的菜单项上都会有一个字符。
Windows 10 让它变得更容易。您可以:
SHIFT + 鼠标右键单击一个文件夹,你会得到一个菜单项 Open PowerShell window here。
或者您可以:
文件 -> 打开 Windows PowerShell。
为了奖金......
如果您在 File
上 鼠标右键单击 -> Open Windows PowerShell
,那么您可以Add to Quick Access Toolbar
:
https://i.stack.imgur.com/G5QAG.png
这在这里放了一个方便的图标:
https://i.stack.imgur.com/YIBBm.png
现在您只需单击该图标即可。 :)
我很惊讶没有人给出这个答案,这是最简单的一个。 (必须是年份。)
只需 Shift + 右键单击资源管理器。然后您可以“在此处打开 PowerShell 窗口”。
默认情况下,它可能设置为命令提示符。如果是这样,您可以在 Windows 10 设置中更改此设置:转到个性化 -> 任务栏并启用“当我右键单击开始按钮或按 Windows 键+X 时,在菜单中将命令提示符替换为 Windows PowerShell”。
我想让这个上下文菜单只有在右键单击并按住“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'"
https://i.stack.imgur.com/daHsy.png
试试 PowerShell PowerToy... 它为 Open PowerShell Here 添加了一个上下文菜单项。
或者,您可以创建一个打开 PowerShell 的快捷方式,其中 Start In 文件夹是您的 Projects 文件夹。
在较新的版本中,当您在空白区域上 Shift+鼠标右键单击 时,默认情况下,Windows 10 在上下文菜单中具有“在此处打开 PowerShell 窗口”,您应该无论如何现在都在使用 Windows Terminal。
在 Windows 8.1 和 Server 2012 R2 中更容易。
这样做一次:右键单击任务栏,选择属性。在导航选项卡中,当我右键单击左下角或按 Windows 键+X 时,打开菜单中的 [✓] 将命令提示符替换为 Windows PowerShell。
然后,每当您需要 PowerShell 提示符时,请按 Win+X, I。(或 Win+X, A 用于 Admin PowerShell 提示符)
为 SVN 制作工具的家伙制作了一个 Windows Explorer 扩展,它至少会打开一个命令提示符窗口。
我还没有尝试过,所以我不知道它是否会做 PowerShell,但我想与我的 Stack Overflow 兄弟分享爱:
http://tools.tortoisesvn.net/StExBar
另一种选择是 Michael Murgolo 在 TechNet 在 http://technet.microsoft.com/en-us/magazine/2008.06.elevation.aspx 上的出色 Elevation PowerToys。
它们包括 PowerShell Prompt Here 和 PowerShell Prompt Here as Administrator。
通过在下面添加注册表项,在 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."
}
您可以从 how to start PowerShell from Windows Explorer 下载详细脚本
一种相当简单的替代方法是通过快捷方式调用 PowerShell。有一个标记为“开始于”的快捷方式属性,说明调用快捷方式时要使用的目录(文件夹)。
如果 Start In 框为空,则表示使用当前目录。
当您第一次以通常的方式创建 PowerShell 的快捷方式时,开始在框中指定主目录。如果你把 start in 框空白,你现在有一个 powershell 的快捷方式,可以在当前目录中打开 PS,不管是什么。
如果您现在将此快捷方式复制到目标目录,并使用资源管理器调用它,您将启动一个指向目标目录的 PS。
这个问题已经有一个公认的答案,但我将其作为另一种方式提供。
对于自动热键用户,这是我正在使用的一个片段
按 Ctrl-Alt-T
时,它会打开 PowerShell 窗口。 (用Win10测试)
如果您的“活动窗口”是 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
https://i.stack.imgur.com/7fO0w.jpg
这会将注册表项的所有者更改为管理员并添加上下文菜单
Change registry to enable PS and CWD context menus
只有这在 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 "写主机 "Hello World""
不定期副业成功案例分享