Is there a way to resolve a .lnk target that works for links that end up in c:\windows\installer?

孤人 提交于 2019-12-11 12:27:44

问题


The usual way to resolve lnk involve using WShell.WshShortcut or IShellLink that way :

var WshShell = WScript.CreateObject("WScript.Shell");
var oShellLink = WshShell.CreateShortcut(strDesktop + "\\some-shortcut.lnk");
WScript.Echo(oShellLink.TargetPath)

But there are links that can't be resolved that way : the resolution end up in c:\windows\installer\{some-guid}\python_icon.exe for example. Most Office programs have this issue too.

CodeProject has another solution done by reverse engineering the lnk format http://www.codeproject.com/KB/shell/ReadLnkFile.aspx but it does not works in thoses cases.

Is there any other way ?

What is this c:\Windows\Installer folder ? And what is this something_icon.exe that is put in it ?


回答1:


Ok I've found the solution here : http://social.msdn.microsoft.com/Forums/en-US/winformssetup/thread/2df18f93-77d8-4217-94a1-6cbe5333a6c4

Since these lnk are MSI lnk you have to use Msi functions to resolve the path :

TCHAR pc [50] = {0};
TCHAR feat [100] = {0};
TCHAR comp [50] = {0};
int b=MsiGetShortcutTarget("Python (command line).lnk",pc,feat,comp);

TCHAR pth [500] = {0};
DWORD chs = 500;
int i = MsiGetComponentPath (pc, comp, pth, &chs);

pth contains the path.



来源:https://stackoverflow.com/questions/964444/is-there-a-way-to-resolve-a-lnk-target-that-works-for-links-that-end-up-in-c-w

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