有没有办法从Windows资源管理器启动PowerShell在一个特定的文件夹,例如右键单击一个文件夹,并有一个选项,如“打开PowerShell在这个文件夹”?
每天我第一次运行MSBuild时,都要更改项目文件夹的目录,这真的很烦人。
有没有办法从Windows资源管理器启动PowerShell在一个特定的文件夹,例如右键单击一个文件夹,并有一个选项,如“打开PowerShell在这个文件夹”?
每天我第一次运行MSBuild时,都要更改项目文件夹的目录,这真的很烦人。
当前回答
一个相当简单的替代方法是通过快捷方式调用PowerShell。有一个标记为“Start in”的快捷方式属性,它表示在调用快捷方式时使用哪个目录(文件夹)。
如果“起始位置”框为空,则表示使用当前目录。
当您第一次以通常的方式创建PowerShell的快捷方式时,start in框指定了主目录。如果你清空start in框,你现在有一个powershell的快捷方式,在当前目录下打开PS,不管那是什么。
如果现在将该快捷方式复制到目标目录,并使用资源管理器调用它,那么将启动指向目标目录的PS。
这个问题已经有了一个公认的答案,但我提供了另一种方式。
其他回答
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的详细脚本
如果你使用的是Windows 8或更高版本,你可以简单地使用内置的文件→“打开Windows PowerShell”。
或者Alt + F + R。
在最新版本的Windows 10中,当你用鼠标Shift+右键点击空白区域时,默认在上下文菜单中有“在此打开PowerShell窗口”,现在你应该已经在使用Windows终端了。
只有在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