Get target of Windows .lnk shortcut using “Start i

2020-06-22 01:35发布

问题:

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:

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?