有没有办法从Windows资源管理器启动PowerShell在一个特定的文件夹,例如右键单击一个文件夹,并有一个选项,如“打开PowerShell在这个文件夹”?
每天我第一次运行MSBuild时,都要更改项目文件夹的目录,这真的很烦人。
有没有办法从Windows资源管理器启动PowerShell在一个特定的文件夹,例如右键单击一个文件夹,并有一个选项,如“打开PowerShell在这个文件夹”?
每天我第一次运行MSBuild时,都要更改项目文件夹的目录,这真的很烦人。
当前回答
另一个选择是Michael Murgolo在TechNet网站http://technet.microsoft.com/en-us/magazine/2008.06.elevation.aspx上推出的Elevation PowerToys。
它们包括PowerShell提示符在这里和PowerShell提示符在这里作为管理员。
其他回答
在Windows资源管理器中,只需转到顶部的地址栏(键盘快捷键:Alt+D或Ctrl+L),输入powershell或powershell_ise并按Enter。将打开一个PowerShell命令窗口,其中包含当前目录。
在最新版本的Windows 10中,当你用鼠标Shift+右键点击空白区域时,默认在上下文菜单中有“在此打开PowerShell窗口”,现在你应该已经在使用Windows终端了。
对于自动热键用户,这里有一个片段我正在使用
当按Ctrl-Alt-T时,它会打开PowerShell窗口。(Win10测试)
如果您的“活动窗口”是Windows资源管理器窗口,那么PowerShell将在当前文件夹中打开。否则,只需在某个默认文件夹中打开PowerShell。
使用方法:1)安装AutoHotkey,复制粘贴到myscript。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
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资源管理器中下载如何启动PowerShell的详细脚本
我创建了一个完全自动化的解决方案来添加PS和CMD上下文项。 只需运行set_registry。cmd,它将更新注册表添加两个按钮时,点击人民币的文件夹或在一些打开的文件夹:
这将更改注册表项的所有者为admin并添加上下文菜单 更改注册表以启用PS和CWD上下文菜单