Get target of Windows .lnk shortcut using “Start in” directory

房东的猫 提交于 2019-12-05 00:57:07

问题


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?

来源:https://stackoverflow.com/questions/29523076/get-target-of-windows-lnk-shortcut-using-start-in-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!