program tip

PowerShell을 사용하여 바로 가기를 만드는 방법

radiobox 2020. 10. 12. 07:25
반응형

PowerShell을 사용하여 바로 가기를 만드는 방법


이 실행 파일에 대해 PowerShell을 사용하여 바로 가기를 만들고 싶습니다.

C:\Program Files (x86)\ColorPix\ColorPix.exe

어떻게 할 수 있습니까?


powershell의 기본 cmdlet을 모르지만 대신 com 개체를 사용할 수 있습니다.

$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$Home\Desktop\ColorPix.lnk")
$Shortcut.TargetPath = "C:\Program Files (x86)\ColorPix\ColorPix.exe"
$Shortcut.Save()

$ pwd에 set-shortcut.ps1로 저장하는 powershell 스크립트를 만들 수 있습니다.

param ( [string]$SourceExe, [string]$DestinationPath )

$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut($DestinationPath)
$Shortcut.TargetPath = $SourceExe
$Shortcut.Save()

이렇게 부르세요

Set-ShortCut "C:\Program Files (x86)\ColorPix\ColorPix.exe" "$Home\Desktop\ColorPix.lnk"

대상 exe에 인수를 전달하려면 다음을 수행하십시오.

'Set the additional parameters for the shortcut  
$Shortcut.Arguments = "/argument=value"  

$ Shortcut.Save () 전에 .

편의를 위해 set-shortcut.ps1의 수정 된 버전이 있습니다. 두 번째 매개 변수로 인수를받습니다.

param ( [string]$SourceExe, [string]$ArgumentsToSourceExe, [string]$DestinationPath )
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut($DestinationPath)
$Shortcut.TargetPath = $SourceExe
$Shortcut.Arguments = $ArgumentsToSourceExe
$Shortcut.Save()

PowerShell을 5.0부터 New-Item, Remove-Item그리고 Get-ChildItem생성 및 기호 링크 관리를 지원하도록 향상되었습니다. ItemType 매개 변수 New-Item는 새 값인 SymbolicLink 승인합니다. 이제 New-Item cmdlet을 실행하여 한 줄에 심볼릭 링크를 만들 수 있습니다.

New-Item -ItemType SymbolicLink -Path "C:\temp" -Name "calc.lnk" -Value "c:\windows\system32\calc.exe"

주의 하시고 SymbolicLink가 A로부터 다른 바로 가기 단축키는 파일입니다. 그것들은 크기 (가리키는 위치를 참조하는 작은 크기)를 가지며 사용하려면 해당 파일 유형을 지원하는 응용 프로그램이 필요합니다. 심볼릭 링크는 파일 시스템 수준이며 모든 것이 원본 파일로 간주합니다. 응용 프로그램은 심볼릭 링크를 사용하기 위해 특별한 지원이 필요하지 않습니다.

어쨌든 Powershell을 사용하여 관리자 권한 으로 실행 바로 가기 를 만들려면 다음을 사용할 수 있습니다.

$file="c:\temp\calc.lnk"
$bytes = [System.IO.File]::ReadAllBytes($file)
$bytes[0x15] = $bytes[0x15] -bor 0x20 #set byte 21 (0x15) bit 6 (0x20) ON (Use –bor to set RunAsAdministrator option and –bxor to unset)
[System.IO.File]::WriteAllBytes($file, $bytes)

.LNK 파일에서 다른 내용을 변경하려면 공식 Microsoft 문서를 참조하십시오 .

참고 URL : https://stackoverflow.com/questions/9701840/how-to-create-a-shortcut-using-powershell

반응형