使用Powershell编辑快捷方式(.lnk)属性
我发现一个讨厌的VBS方法来做到这一点,但是我正在寻找一个本地的PoSh程序来编辑.LNK文件的属性。目标是接触到远程机器,重复现有的快捷方式,其中包含大部分正确的属性,并编辑其中一些。
I've found a nasty VBS way to do this, but I'm looking for a native PoSh procedure to edit the properties of a .LNK file. The goal is to reach out to remote machines, duplicate an existing shortcut with most of the correct properties, and edit a couple of them.
如果只是更容易写一个新的快捷方式文件,这也可以工作。
If it would just be easier to write a new shortcut file, that would work too.
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
找到VB版本代码在这里:
http://www.tutorialized.com/view/tutorial/Extract-the-target-file-from-a-shortcut-file-.lnk/18349
Found the VB version of the code here: http://www.tutorialized.com/view/tutorial/Extract-the-target-file-from-a-shortcut-file-.lnk/18349