从快捷方式打开特定目录中的Powershell

时间:2013-01-09 10:53:28

标签: powershell windows-7 shortcuts

听起来应该这么简单......我一定是傻了。

我想要的只是创建一个Windows快捷方式,将Powershell打开到特定目录:

我正在使用目标:

%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe 
    -noexit -command {cd c:/path/to/open}

把它作为文本吐出命令。

9 个答案:

答案 0 :(得分:104)

或使用:powershell.exe -noexit -command "cd c:\temp "

答案 1 :(得分:34)

您还可以将“开始”快捷方式字段设置为所需位置。

答案 2 :(得分:5)

尝试:

%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe 
-noexit -command "cd c:/path/to/open"

答案 3 :(得分:4)

为Powershell定义一个快捷方式,并打开其属性,最后在“开始”中键入触发Powershell快捷方式时要打开的文件夹目标

答案 4 :(得分:3)

好的 - 你需要使用&参数来指定它的powershell命令&语法略有不同:

%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe 
-noexit -command "& {cd c:\path\to\open}"

答案 5 :(得分:2)

如果您希望powershell以管理员身份启动并在特定目录中运行,即使在不同的驱动器上运行,最好使用Set-Location命令。请按照以下步骤操作

  1. 创建一个ShortCutLink,其目标是powershellcommand exe。
  2. Start in:留空。 (通常在空白时从当前工作目录开始;但我们不关心。
  3. Target更改为包含powershell和位置的目标:

    C:\Windows\...\v1.0\powershell.exe -noexit -command "Set-Location D:\_DCode\Main"

  4. 点击Advanced...,然后选择Run as administrator
  5. 点击OK
  6. 不要忘记从Colors标签更改快捷方式颜色的方便技巧。这样,如果您有两个或更多链接打开PowerShell窗口,看到不同的颜色可以直观地告诉您哪个shell正在工作。

答案 6 :(得分:1)

将此代码复制到记事本中并使用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'"

答案 7 :(得分:1)

如果有人想要一个资源管理器右键单击选项运行此脚本:

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."
}

这就是现在所示:

enter image description here

请注意,您可以从how to start PowerShell from Windows Explorer下载详细的脚本。

答案 8 :(得分:0)

我只想添加我的Developer Powershell链接...作为记录。

C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -noe -c "&{Import-Module """C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"""; Enter-VsDevShell d998f19b; cd c:\dev\}"

这将在c:\dev\中启动Developer Powershell(VS 2019)。

相关问题