Open Powershell in a specific directory from shortcut

后端 未结 9 1291
再見小時候
再見小時候 2021-01-30 12:22

This sounds like it should be so simple... I must be dumb.

All I want is to make a windows short-cut that opens Powershell into a specific directory:

I\'m using

9条回答
  •  南方客
    南方客 (楼主)
    2021-01-30 13:10

    If one wants a explorer right click options run this script:

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

    This is what is shown now:


    Note that you can download a detailed script from how to start PowerShell from Windows Explorer.

提交回复
热议问题