Article View: borland.public.cppbuilder.nativeapi
Article #10200Re: ShellExecute on LNK files
From: Marc
Date: Tue, 04 May 2004 15:23
Date: Tue, 04 May 2004 15:23
57 lines
2790 bytes
2790 bytes
I am sure I am not the only one with this problem, so here is
the solution I have found for anyone who is interested.
This code will return the Name of the EXE the OfficeXP of Office 2003 LNK file is pointing to. This will not return the
ICONS.EXE file but the actual application the LNK file is
pointing to.
string FileInfo::ExtractExeNameFromLNKFile(string strFileNameAndPath)
{
string strExeName = "";
if (IsLNKFile(strFileNameAndPath))
{
IShellLink* psl;
IPersistFile* ppf;
HRESULT hres;
char szEXEPath[MAX_PATH];
CoInitialize(NULL);
// Get a pointer to the IShellLink interface.
hres = ::CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)&psl);
if (SUCCEEDED(hres))
{
// Get a pointer to the IPersistFile interface.
hres = psl->QueryInterface(IID_IPersistFile, (void**)&ppf);
if (SUCCEEDED(hres))
{
// Ensure string is Unicode.
wchar_t lpWideCharStr[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, strFileNameAndPath.c_str(), -1, lpWideCharStr, MAX_PATH);
hres = ppf->Load(lpWideCharStr, STGM_READ);
if (SUCCEEDED(hres))
{
LPITEMIDLIST pidl;
psl->Resolve(NULL, SLR_INVOKE_MSI | SLR_NOUPDATE | SLR_NO_UI);
psl->GetIDList(&pidl);
SHGetPathFromIDList(pidl, szEXEPath);
}
}
// Release the pointer to the IPersistFile interface.
ppf->Release();
}
// Release the pointer to the IShellLink interface.
hres = psl->Release();
CoUninitialize();
strExeName = (string)szEXEPath;
}
return strExeName;
}
Technical Details
Message-ID:
<4097b57a$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!controlnews3.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<408036d4$1@newsgroups.borland.com> <409008c6$3@newsgroups.borland.com> <409009dd$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,7148159e8e963fa1 X-Google-Attributes: gid10cc67,public From: "Marc" <Bukwheat@axess.com> Sender: "Marc" <Bukwheat@axess.com> Reply-To: "Marc" <Bukwheat@axess.com> Subject: Re: ShellExecute on LNK files Newsgroups: borland.public.cppbuilder.nativeapi X-User-Info: 138.11.254.204 X-Forwarded-For: unknown References: <408036d4$1@newsgroups.borland.com> <409008c6$3@newsgroups.borland.com> <409009dd$1@newsgroups.borland.com> NNTP-Posting-Host: 207.105.83.66 Message-ID: <4097b57a$1@newsgroups.borland.com> Date: 4 May 2004 08:23:38 -0700 X-Trace: newsgroups.borland.com 1083684218 207.105.83.66 (4 May 2004 08:23:38 -0700) Lines: 58 Path: arc1-ca.pugleaf.net!controlnews3.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail