我希望能够找到开始菜单文件夹中快捷方式的目标路径,
我知道应该使用shell link组件对象模型,
但在我的测试中,对于某些快捷方式,它显示:
如何找到这些产品的目标路径。
这是我使用的函数:
我知道应该使用shell link组件对象模型,
但在我的测试中,对于某些快捷方式,它显示:
"windows\installer\{guid}\x.exe"
并没有显示程序文件夹,而对于其他快捷方式则正常工作,如何找到这些产品的目标路径。
这是我使用的函数:
HRESULT TargetShortcut::ResolveIt(HWND hwnd, LPCTSTR lpszLinkFile, LPTSTR lpszPath, int iPathBufferSize)
{
HRESULT hres;
if (lpszPath == NULL)
return E_INVALIDARG;
*lpszPath = 0;
// Get a pointer to the IShellLink interface. It is assumed that CoInitialize
// has already been called.
IShellLink* __psl = NULL;
HRESULT hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl);
if (SUCCEEDED(hres))
{
// Get a pointer to the IPersistFile interface.
IPersistFile* ppf = NULL;
hres = __psl->QueryInterface(IID_IPersistFile, (void**)&ppf);
if (SUCCEEDED(hres))
{
// Add code here to check return value from MultiByteWideChar
// for success.
// Load the shortcut.
#ifdef _UNICODE
hres = ppf->Load(lpszLinkFile, STGM_READ);
#else
WCHAR wsz[MAX_PATH] = {0};
// Ensure that the string is Unicode.
MultiByteToWideChar(CP_ACP, 0, lpszLinkFile, -1, wsz, MAX_PATH);
hres = ppf->Load(wsz, STGM_READ);
#endif
if (SUCCEEDED(hres))
{
// Resolve the link.
hres = __psl->Resolve(hwnd, 0);
if (SUCCEEDED(hres))
{
// Get the path to the link target.
TCHAR szGotPath[MAX_PATH] = {0};
hres = __psl->GetPath(szGotPath, _countof(szGotPath), NULL, SLGP_SHORTPATH);
if (SUCCEEDED(hres))
{
hres = StringCbCopy(lpszPath, iPathBufferSize, szGotPath);
}
}
}
// Release the pointer to the IPersistFile interface.
ppf->Release();
}
// Release the pointer to the IShellLink interface.
__psl->Release();
}
return hres;
}
以下是关于快捷方式的答案:
C:\Windows\Installer{53FA9A9F-3C19-4D43-AD6B-DEF365D469BA}
SFGAO_FILESYSTEM
属性。即使它不是磁盘上的文件,如果您请求路径,它们也会编造一个人工路径。这就是您在此处获得的内容。它是动态安装程序的人工路径。 - Raymond Chen