source

숏컷에서 특정 디렉토리의 Powershell을 엽니다.

manysource 2023. 4. 15. 09:03

숏컷에서 특정 디렉토리의 Powershell을 엽니다.

Powershell을 특정 디렉토리로 여는 바로 가기를 만들려면 어떻게 해야 합니까?

예를 들어 다음과 같습니다.

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

하지만 그건 명령어를 텍스트로 내뱉는 거야. 어떻게?

이 명령어를 사용합니다.

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

-NoExit: startup 명령어를 실행한 후 종료하지 마십시오.

또한 "시작 위치" 바로 가기 필드를 원하는 위치로 설정할 수도 있습니다.

OK - 를 사용해야 합니다.&powershell 명령어를 지정하는 파라미터와 구문이 약간 다릅니다.

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

Powershell 바로 가기를 정의하고 속성을 연 다음 마지막으로 "시작"에 Powershell 바로 가기를 트리거할 때 열 폴더 대상을 입력합니다.

powershell을 admin으로 시작하여 다른 드라이브에서도 특정 디렉토리에서 실행하려면Set-Location명령어를 입력합니다.다음의 순서에 따라 주세요.

  1. 대상이 powershell 명령어 exe인 ShortCutLink를 만듭니다.
  2. 떠나Start in:blank. (보통 공백일 때 현재 작업 디렉토리에서 시작되지만 상관없습니다.)
  3. 바꾸다Target타겟과 함께 powershell 및 장소:

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

  1. 클릭Advanced...를 선택합니다.Run as administrator.
  2. 클릭OK아웃입니다.

숏컷의 색상을 변경하기 위한 편리한 요령을 잊지 마십시오.Colors이렇게 하면 파워셸 창을 여는 링크가 두 개 이상 있는 경우 다른 색상을 보면 어떤 셸에서 작동하는지 시각적으로 알 수 있습니다.

시험:

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

탐색기를 마우스 오른쪽 버튼으로 클릭하고 싶은 경우 다음 스크립트를 실행합니다.

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을 시작하는 방법에서 자세한 스크립트를 다운로드할 수 있습니다.

이 코드를 메모장에 복사하여 레지스트 확장자로 저장합니다.결과 파일을 더블 클릭합니다.레지스트리로 가져오기에 대한 메시지가 표시되면 yes를 클릭한 다음 OK를 클릭합니다.탐색기에서 원하는 폴더로 이동하여 상황에 맞는 메뉴를 표시합니다.보통 마우스 오른쪽 버튼을 클릭하면 됩니다.


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'"

우선 명령줄 셸을 사용하여 Windows 터미널을 시작하는 경우 다음을 사용할 수 있습니다.

wt.exe -d "c:\temp"

.ps1 스크립트 파일을 사용하여 태스크바의 바로 가기에서 특정 경로로 PowerShell 터미널을 엽니다.스크립트:

cd 'directory path'
powershell

PowerShell 터미널에서 "powershell.exe"를 실행하면 새로운 PowerShell 세션이 시작되어 터미널 창이 닫히지 않습니다.

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

Developer 2019 Developer Powershell(VS 2019)의 Developer Powershell(VS 2019)이됩니다.c:\dev\.

「 」를 사용하고 Powershell 7 (pwsh) 「」를 사용합니다.-WorkingDirectory다음과 같이 합니다.

pwsh -WorkingDirectory "C:\path\to\your\directory"

언급URL : https://stackoverflow.com/questions/14233659/open-powershell-in-a-specific-directory-from-shortcut