5

I am trying to retrieve the target path of a Windows .lnk shortcut, but the "Target" is not an actual file path according to the .lnk file's properties:

enter image description here

I am using the IWshRuntimeLibrary and the shortcut object I am accessing is of type IWshShortcut:

WshShell shell = new WshShell();
IWshShortcut link = (IWshShortcut)shell.CreateShortcut(lnkFileName);
// This returns "C:\Windows\Installer\{F843C6A3-224D-4615-94F8-3C461BD9AEA0}\PaintShopProExeIcon.ico"
var targetPath = link.TargetPath;
// This is the same as the "Start in" value in the image above
var workingDir = link.WorkingDirectory;

The TargetPath property of the "link" object is not the location of the actual .exe: "C:\Windows\Installer{F843C6A3-224D-4615-94F8-3C461BD9AEA0}\PaintShopProExeIcon.ico"

I can get the WorkingDirectory property from this object, which seems to be the same as the "Start in" property of the shortcut as in the image above. My question is, how can I get the actual target path of the .exe file the shortcut would open, if TargetPath is not the actual .exe path? Where is this information?

The actual target path in this example is "C:\Program Files (x86)\Jasc Software Inc\Paint Shop Pro 9\Paint Shop Pro 9.exe". How does the system know to open "Paint Shop Pro.exe" specifically?

kreddkrikk
  • 389
  • 3
  • 12
  • 3
    Looks like a crappy trick called advertised shortcuts. Tends to be used to "self-heal" an install, a program like this will try to steal file associations back. Or create desktop icons to programs that are not installed yet. Best Google query is "msi advertised shortcut". – Hans Passant Apr 08 '15 at 20:41
  • 3
    Thanks. I found a solution at http://www.geektieguy.com/2007/11/19/how-to-parse-special-lnk-files-aka-msi-shortcuts-aka-windows-installer-advertised-shortcuts-using-c/, which detects the actual target's path of an advertised shortcut. – kreddkrikk Apr 09 '15 at 00:04

0 Answers0