[英]Why in finding target path of shortcut with shell link in c++ it refers to windows\installer folder
I want to find target path of a shortcut in startmenu folder ,我想在 startmenu 文件夹中找到快捷方式的目标路径,
I know that should use from shell link component object model ,我知道应该使用来自 shell 链接组件对象模型,
But in my test for some shortcuts it shows:但在我对一些快捷方式的测试中,它显示:
"windows\\installer\\{guid}\\x.exe " “windows\\安装程序\\{guid}\\x.exe ”
and does not show program files folder for it , and for other shortcut works fine, 并且不显示它的程序文件文件夹,并且其他快捷方式工作正常, 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; }
and this an answer for a shortcut :这是一个快捷方式的答案:
C:\\Windows\\Installer{53FA9A9F-3C19-4D43-AD6B-DEF365D469BA}
Try first this code:先试试这个代码:
#include "msi.h"
#pragma comment (lib, "msi")
...
TCHAR Path[MAX_PATH];
Path[0] = '\0';
TCHAR pszComponentCode[MAX_FEATURE_CHARS+1];
TCHAR pszProductCode[MAX_FEATURE_CHARS+1];
pszComponentCode[0] = _T('\0');
pszProductCode[0] = _T('\0');
if ( MsiGetShortcutTarget(pszLinkPathName, pszProductCode, NULL, pszComponentCode) == ERROR_SUCCESS)
{
DWORD dw = MAX_PATH;
UINT ret = MsiGetComponentPath(pszProductCode, pszComponentCode, Path, &dw);
//Path now contains path to EXE
}
else
{
//process regular LNK
}
Then in ELSE part you can call code to resolve regular LNK然后在 ELSE 部分,您可以调用代码来解析常规 LNK
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.