Jump to content
  • Advertisement
Sign in to follow this  
nekobasu33

How to find out if ".lnk" file (windows shortcut) is linking to ".exe" file

This topic is 4077 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Does anybody know how to find out if .lnk file is linking to an .exe (Application file) For example: Calculator.lnk is actually linking to an Application file in C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories, and the application is called Calculator.exe I am programming using Win32 and C++. Any help would be appreciated. Thank you.

Share this post


Link to post
Share on other sites
Advertisement
Not all shortcuts are to executables. You can have shortcuts to folders, documents, shell objects, etc. If you want to find what a given link refers to you can use IShellLink::Resolve(). It's not pretty though. Q179904 gives an example of how to use IShellLink.

Share this post


Link to post
Share on other sites
It's not too bad of a process to resolve a link:


IShellLink *psl;
HRESULT hr = CoCreateInstance(__uuidof(IShellLink), NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&psl));
if (SUCCEEDED(hr))
{
IPersistFile *ppf;
hr = psl->QueryInterface(IID_PPV_ARGS(&ppf));
if (SUCCEEDED(hr))
{
hr = ppf->Load(pszPathToLnkFile, STGM_READ);
if (SUCCEEDED(hr))
{
hr = psl->Resolve(NULL, SLR_NOLINKINFO | SLR_NO_UI | SLR_NOUPDATE | SLR_NOSEARCH | SLR_NOTRACK);
if (SUCCEEDED(hr))
{
WCHAR szPath[MAX_PATH];
hr = psl->GetPath(szPath, ARRAYSIZE(szPath), NULL, 0);
if (SUCCEEDED(hr))
{
// Do whatever with the path
}
}
}
ppf->Release();
}
psl->Release();
}

Share this post


Link to post
Share on other sites
Colin,

Thank you for your sample code.

I have a question about the code, though, where is it in there actually trying to to detect whether a '.lnk' file is linking to a '.exe' file or some other file extension?

Or do you mean to find the path where the .lnk file is linking and in the "// Do whatever with the path" section, after we figure out the path, we have to figure out of the last 3 letter of the file whether it is 'exe' or something else?

Share this post


Link to post
Share on other sites
There's an error when I use "IID_PPV_ARGS" , it says: error C3861: 'IID_PPV_ARGS': identifier not found

I tried including "objbase.h", but it still doesn't work. Do you have any idea what file I need to include to use "IID_PPV_ARGS"?

Thanks.

Share this post


Link to post
Share on other sites
I have installed the latest Windows SDK, but I still get the same error message.

error C3861: 'IID_PPV_ARGS': identifier not found

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!