首页 文章

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

提问于
浏览
61

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

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

我正在使用目标:

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

把它作为文本吐出命令 .

7 回答

  • 0

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

  • 3

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

  • 97

    尝试:

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

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

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

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

    您可以从how to start PowerShell from Windows Explorer下载详细脚本

    enter image description here

  • 32

    如果您希望powershell以管理员身份启动并在特定目录中运行,即使在不同的驱动器上运行,最好使用 Set-Location 命令 . 跟着这些步骤

    • 创建一个ShortCutLink,其目标是powershellcommand exe .

    • 留空 Start in: 空白 . (通常这在空白时从当前工作目录开始;但我们不关心 . )

    • 使用PowerShell和位置的目标更改 Target

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

    • 单击 Advanced... 并选择 Run as administrator .

    • 单击 OK s .


    不要忘记从 Colors 选项卡更改快捷方式颜色的方便技巧 . 这样,如果你有两个或多个链接打开PowerShell窗口,看到不同的颜色可以在视觉上让你知道哪个shell工作 .

相关问题