• 12
• 27
• 9
• 20
• 33

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

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

## 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 on other sites
all .lnk files link to an .exe. it's what they are: shortcuts to .exe files

at least according to this...
http://filext.com/file-extension/LNK

Do you mean to ask: how do i find out what EXE a LNK file links to?

-me

##### Share on other sites
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 on other sites

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 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 on other sites
The part where it says "//Do whatever with the path" is where you determine whether the target is an EXE or something. I recommend using PathIsExe().

##### 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 on other sites
You need to have the latest Platform SDK. Clicky.

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