Your strategic advantage starts here

Use PowerShell to Find an Advertised Shortcut Target

Use PowerShell to Find an Advertised Shortcut Target

Have you ever looked at the target of an .lnk shortcut and it appears to be greyed out/disabled? Chances are it is a Windows Installer advertised shortcut, which is used as part of Windows Installer resiliency and self healing. Instead of it typically pointing to an executable, it invokes the Windows Installer subsystem to locate the shortcut target instead.

You can use PowerShell to find an advertised shortcut target like so:

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
}

$pathToLnk = Get-AdvertisedShortcut "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\InstEd.lnk"
Related Posts
Leave a Reply
Give us a call

Available from 9am to 8pm, Monday to Friday.

Send us a message

Send your message any time you want.

Our usual reply time: 1 Business day
Give us a call

Available from 9am to 8pm, Monday to Friday.

Send us a message

Send your message any time you want.

Our usual reply time: 1 Business day