且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用 powershell 获取快捷方式 (.lnk) 文件的目标

更新时间:2023-01-31 12:09:01

您在属性中犯了错误;正如 wOxxOm 建议的那样,您应该使用 TargetPath 而不是 Target:

You have made an error in the property; as wOxxOm suggests, you should be using TargetPath rather than Target:

$sh = New-Object -ComObject WScript.Shell
$target = $sh.CreateShortcut('<full-path-to-shortcut>').TargetPath

Google 和 MSDN 在这方面确实很有帮助;此外,将对象传递给 Get-Member 通常很有用且具有教育意义.这个问题还展示了如何使用 PowerShell 操作快捷方式,并使用相同的技术如此处所示.

Google and MSDN were indeed helpful here; additionally, piping objects to Get-Member can often be useful and educational. This question also shows how to manipulate shortcuts using PowerShell, and uses the same technique as seen here.

如果您还需要可执行文件的参数,则将它们单独存储:

If you want the arguments to the executable as well, those are stored separately:

$arguments = $sh.CreateShortcut('<full-path-to-shortcut>').Arguments

同样,将对象传递给 Get-Member - 在这种情况下,由 WScript.Shell.CreateShortcut() 返回的对象 - 提供了有用的信息.

Again, piping objects to Get-Member - in this case, the object returned by WScript.Shell.CreateShortcut() - provides useful information.