PowerShell을 사용하여 바로 가기 (.lnk) 속성 편집
-
20-08-2019 - |
문제
이 작업을 수행하는 불쾌한 VBS 방법을 찾았지만 .lnk 파일의 속성을 편집하기위한 기본 포쉬 절차를 찾고 있습니다. 목표는 원격 기계에 연락하고 대부분의 올바른 속성으로 기존 단축키를 복제하고 몇 가지를 편집하는 것입니다.
새 바로 가기 파일을 작성하는 것이 더 쉬운 경우에도 효과가 있습니다.
해결책
Copy-Item $sourcepath $destination ## Get the lnk we want to use as a template
$shell = New-Object -COM WScript.Shell
$shortcut = $shell.CreateShortcut($destination) ## Open the lnk
$shortcut.TargetPath = "C:\path\to\new\exe.exe" ## Make changes
$shortcut.Description = "Our new link" ## This is the "Comment" field
$shortcut.Save() ## Save
여기에서 Code의 VB 버전을 찾았습니다.http://www.tutorialized.com/view/tutorial/extract-the-target-file-from-a-shortcut-file-.lnk/18349
다른 팁
다음은 .lnk 파일을 처리하는 데 사용하는 기능입니다. 그들은 발견 된 함수의 수정 된 버전입니다 여기 @Nathan Hartley가 언급했듯이. 나는 개선했다 Get-Shortcut
와일드 카드를 처리합니다 *
문자열을 통과시켜 dir
파일 인포 객체 세트로 확장합니다.
function Get-Shortcut {
param(
$path = $null
)
$obj = New-Object -ComObject WScript.Shell
if ($path -eq $null) {
$pathUser = [System.Environment]::GetFolderPath('StartMenu')
$pathCommon = $obj.SpecialFolders.Item('AllUsersStartMenu')
$path = dir $pathUser, $pathCommon -Filter *.lnk -Recurse
}
if ($path -is [string]) {
$path = dir $path -Filter *.lnk
}
$path | ForEach-Object {
if ($_ -is [string]) {
$_ = dir $_ -Filter *.lnk
}
if ($_) {
$link = $obj.CreateShortcut($_.FullName)
$info = @{}
$info.Hotkey = $link.Hotkey
$info.TargetPath = $link.TargetPath
$info.LinkPath = $link.FullName
$info.Arguments = $link.Arguments
$info.Target = try {Split-Path $info.TargetPath -Leaf } catch { 'n/a'}
$info.Link = try { Split-Path $info.LinkPath -Leaf } catch { 'n/a'}
$info.WindowStyle = $link.WindowStyle
$info.IconLocation = $link.IconLocation
New-Object PSObject -Property $info
}
}
}
function Set-Shortcut {
param(
[Parameter(ValueFromPipelineByPropertyName=$true)]
$LinkPath,
$Hotkey,
$IconLocation,
$Arguments,
$TargetPath
)
begin {
$shell = New-Object -ComObject WScript.Shell
}
process {
$link = $shell.CreateShortcut($LinkPath)
$PSCmdlet.MyInvocation.BoundParameters.GetEnumerator() |
Where-Object { $_.key -ne 'LinkPath' } |
ForEach-Object { $link.$($_.key) = $_.value }
$link.Save()
}
}
나는 기본적인 방법이 있다고 생각하지 않습니다.
이 협력이 있습니다. 바로 가기 .exe.
UTIL을 원격 시스템에 복사 한 다음 WMI를 사용하여 호출하여 원하는 변경 사항을 변경해야합니다.
더 쉬운 방법은 새 파일을 덮어 쓰고/또는 작성하는 것이라고 생각합니다.
원격 공유를 통해 이러한 시스템에 액세스 할 수 있습니까?
@jasonmarcher의 답변에 짧은 추가 ..
사용 가능한 속성을 보려면 방금 실행할 수 있습니다 $shortcut
~ 후에 $shortcut = $shell.CreateShortcut($destination)
안에 추신. 이것은 모든 속성과 현재 값을 인쇄합니다.