powershell get-terververtisedShortCut
当我发现有时无法通过 wscript.shell 对象查询快捷方式目标之后,但是如果需要通过 windowsinstaller.installer.installer 对象查询捷径,我搜索了网络并在下面找到了有希望的解决方案。
但是,要么为另一个版本的Windows编写解决方案(我在64位Windows 10上使用PowerShell 5.1)。 给我提供以下广告快捷方式的错误
Ausnahme beim Aufrufen von "InvokeMember" mit 5 Argument(en): "ShortcutTarget"
它仅
Exception while calling "InvokeMember" with 5 arguments: "ShortcutTarget"
消息行没有其他信息的行:
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : COMException
不幸的是,我不知道在哪里查找正确的语法,除了下面的代码无法解决宣传的目标的原始问题外,别无其他快捷方式。
接下来我可以看什么想法?
function Get-AdvertisedShortcut {
param([string]$pathToLnk)
$shortcutTarget = ""
if ($pathToLnk -ne $null -and (test-path $pathToLnk)) {
$windowsInstaller = New-Object -ComObject WindowsInstaller.Installer
$lnkTarget = $WindowsInstaller.GetType().InvokeMember("ShortcutTarget","GetProperty",$null,$windowsInstaller,$pathToLnk)
$productCode = $lnkTarget.GetType().InvokeMember("StringData","GetProperty",$null,$lnkTarget,1)
$componentCode = $lnkTarget.GetType().InvokeMember("StringData","GetProperty",$null,$lnkTarget,3)
$shortcutTarget = $WindowsInstaller.GetType().InvokeMember("ComponentPath","GetProperty",$null,$WindowsInstaller,@($productCode,$componentCode))
}
return $shortcutTarget
}
After I found out that sometimes shortcut targets cannot be queried by WScript.Shell object, but in case of advertised shortcuts need to be queried by WindowsInstaller.Installer object, I searched the web and found the promising solution below.
But either the solution is outdated or written for another version of Windows (I use PowerShell 5.1 on 64-bit Windows 10). It gives me only the following error message for advertised shortcuts like %AppData%\Microsoft\Windows\Start Menu\Programs\System Tools*.lnk:
Ausnahme beim Aufrufen von "InvokeMember" mit 5 Argument(en): "ShortcutTarget"
which literally translates to:
Exception while calling "InvokeMember" with 5 arguments: "ShortcutTarget"
In addition, I see the following lines with no additional information for me:
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : COMException
Unfortunately, I do not know where to lookup the correct syntax and have found nothing else than the code below for solving the original issue of getting the target of an advertised shortcut.
Any ideas where I can look next?
Code from https://www.alkanesolutions.co.uk/2020/06/03/use-powershell-to-find-an-advertised-shortcut-target:
function Get-AdvertisedShortcut {
param([string]$pathToLnk)
$shortcutTarget = ""
if ($pathToLnk -ne $null -and (test-path $pathToLnk)) {
$windowsInstaller = New-Object -ComObject WindowsInstaller.Installer
$lnkTarget = $WindowsInstaller.GetType().InvokeMember("ShortcutTarget","GetProperty",$null,$windowsInstaller,$pathToLnk)
$productCode = $lnkTarget.GetType().InvokeMember("StringData","GetProperty",$null,$lnkTarget,1)
$componentCode = $lnkTarget.GetType().InvokeMember("StringData","GetProperty",$null,$lnkTarget,3)
$shortcutTarget = $WindowsInstaller.GetType().InvokeMember("ComponentPath","GetProperty",$null,$WindowsInstaller,@($productCode,$componentCode))
}
return $shortcutTarget
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论