这听起来像它应该是如此简单......我一定是愚蠢的。从快捷方式打开特定目录中的Powershell
所有我想要的是使Windows快捷方式打开PowerShell的到特定目录:
我使用的目标:
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe
-noexit -command {cd c:/path/to/open}
把它刚刚吐出来的是命令文本。
任何帮助,将不胜感激。
这听起来像它应该是如此简单......我一定是愚蠢的。从快捷方式打开特定目录中的Powershell
所有我想要的是使Windows快捷方式打开PowerShell的到特定目录:
我使用的目标:
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe
-noexit -command {cd c:/path/to/open}
把它刚刚吐出来的是命令文本。
任何帮助,将不胜感激。
或使用:powershell.exe -noexit -command "cd c:\temp "
好 - 你需要使用&
参数指定这是一个PowerShell的COMAND &语法稍有不同:
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe
-noexit -command "& {cd c:\path\to\open}"
这与[Kayasak解决方案](http:///stackoverflow.com/a/14233773/2707864)? –
我在[Hyper](https://hyper.is)中使用了PowerShell,在'.hyper.js'中,我使用了如下的解决方案:'shellArgs:['-noexit','&{cd“$ HOME \ \我的旧文件“}']'。我无法制作'['-noexit','-command','“cd”$ HOME \\我的旧文档“']'或'['-noexit','-command”cd“$ HOME \\我的旧文件“']'工作。 –
旧帖子,但只是帮助我:)我厌倦了作为管理员卡在system32目录。谢谢 –
尝试:
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe
-noexit -command "cd c:/path/to/open"
您还可以将“开始”(Start in)快捷方式字段设置为您想要的位置。
迄今为止最简单的解决方案,特别是如果您尝试使用带空格的路径或奇怪的字符(例如程序文件(x86)下的任何东西) –
“开始”并不适用于我,仍然在c:\ windows \ system32中启动。 –
是的,如果快捷方式具有“以管理员身份运行“检查。 – Mica
将此密码复制到记事本中,并以reg扩展名的形式保存。 双击生成的文件。如果您收到有关导入注册表的消息,请单击是,然后确定。 导航到资源管理器中的任何文件夹并调出上下文菜单。这通常通过单击鼠标右键完成。
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\Background\shell\PShell]
"MUIVerb"="Open in Powershell Window"
[HKEY_CLASSES_ROOT\Directory\Background\shell\PShell\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."
}
如果你想PowerShell来开始作为管理员,并在特定的目录中运行下载详细的脚本,甚至是不同的驱动器上,最好使用Set-Location
命令。请按照下列步骤操作
Start in:
空白。 (通常这开始于当前的工作目录为空当,但我们不在乎)变化Target
这与你的目标PowerShell和地点:
C:\Windows\...\v1.0\powershell.exe -noexit -command "Set-Location D:\_DCode\Main"
Advanced...
并选择Run as administrator
。OK
s出来。不要忘了方便的技巧,从Colors
标签更改快捷方式的颜色。这样,如果你有两个或两个以上的链接打开PowerShell的窗口,看到不同的颜色可以通过视觉让你知道哪个外壳正在工作英寸
如果路径中有空格,你需要加入''''powershell.exe -noexit -command“cd'c:\ space \ readme.txt'”' – blachniet
正是我在找的东西对于。额外的引号是必要的,包括使用插值路径时。 –
如果我们讨论的是某种快捷方式(如在提示和技巧中),那就是:如果您在Windows资源管理器中的所需文件夹中,可以在地址栏中键入'powershell',它将打开PowerShell at那个位置。这也适用于Windows可以通过PATH环境变量找到的'cmd'和任何其他应用程序。 –