Powershell을 사용하여 바로 가기(.lnk) 속성 편집
이 작업을 수행할 수 있는 좋지 않은 VBS 방법을 찾았지만 의 속성을 편집할 수 있는 기본 PoS 절차를 찾고 있습니다.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
http://www.tutorialized.com/view/tutorial/Extract-the-target-file-from-a-shortcut-file-.lnk/18349 에서 VB 버전의 코드를 찾았습니다.
아래는 제가 .lnk 파일을 처리할 때 사용하는 기능입니다.이들은 @Nathan Hartley가 언급한 바와 같이 여기서 발견된 함수의 수정된 버전입니다.실력이 늘었습니다Get-Shortcut
와 같은 와일드카드를 다루는*
에게 조건부로dir
파일을 FileInfo 개체 집합으로 확장합니다.
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()
}
}
@Jason에 대한 짧은 추가.마쳐의 대답은..
사용 가능한 속성을 보려면 그냥 실행하면 됩니다.$shortcut
끝나고$shortcut = $shell.CreateShortcut($destination)
피에스로모든 속성과 현재 값이 인쇄됩니다.
저는 원주민 방법이 없다고 생각합니다.
다음 DOS 유틸리티가 있습니다.Shortcut.exe.
여전히 유틸리티를 원격 시스템에 복사한 다음 WMI를 사용하여 호출하여 원하는 변경을 수행해야 합니다.
파일을 덮어쓰거나 새 파일을 만드는 것이 더 쉬울 것 같습니다.
원격 공유를 통해 이러한 시스템에 액세스할 수 있습니까?
언급URL : https://stackoverflow.com/questions/484560/editing-shortcut-lnk-properties-with-powershell
'sourcetip' 카테고리의 다른 글
사전 인증 목적인증봄 보안의 토큰? (0) | 2023.08.11 |
---|---|
jquery가 로드되었는지 확인한 후 false이면 로드합니다. (0) | 2023.08.11 |
잡립과 피클의 다른 사용 사례는 무엇입니까? (0) | 2023.08.11 |
Android, TextView의 너비를 제한하는 방법(텍스트 끝에 점 3개 추가)? (0) | 2023.08.11 |
CSS에 패딩이 있을 때 어떻게 하면 텍스트 영역을 100% 너비로 넘치지 않게 만들 수 있습니까? (0) | 2023.08.11 |