Windows - find the target of a shortcut (.lnk)

Joined
Jun 24, 2001
Messages
974
I have been asked to produce a quick little app that will find the targets of all shortcuts in a given directory. I have googled around a bit, but not found anything that looks relatively simple yet.

I am open to C++/C#/VB.net, and was wondering if anyone here has looked into this before and found a clean solution.

Thanks,
The Bryophyte
 
It appears you will have to do something similar to what is described on this page from the MSDN. I haven't been able to find anything faster, easier or doable in .NET.

202276
 
It's easy to do. The specific solution depends on what language you use; when you choose one of those that you list, let us know.

In general, you'll just enumerate the file of the directory, then check each one to see if it has the extension "LNK". If it does, it is a candidate for your processing.
 
I think I'll go with VB for this. Not sure I feel like writing the lines of code required to do something so small in C++. So, any VB suggestions other than what Tytalus turned up? I will just head in that direction and see if I can get it done unless someone has a new idea.
 
if you can use autoit, there's a function just for that, which would require little effort to use, depending on what you need to do in the end.

http://www.autoitscript.com/autoit3/docs/functions/FileGetShortcut.htm

that being said, since there is in fact that function in autoit, i would guess that it would be pretty easy to do it manually with the windows api, since many functions in autoit seem to correspond directly to windows api functions
 
I will have to play with AutoIT. I was trying to limit myself to languages that our developers use for the sake of maintenance, but they are pretty limited and if my little app to find shortcut targets needs to be maintained, I've done something horribly wrong.

Since it looks like AutoIT will not require a runtime on the host machine, it should be okay.
 
Are you using VB, or VB.Net? One post says "VB", the other says "VB.Net".
 
It looks like you can do this with some of the windows APIs, but not specifically through .NET. I recently created shortcuts using the Interop.IWshRuntimeLibrary.dll. After some quick googling, it looks like there are a number of wrapper classes that make this functionality easy, such as this one. Hope this helps.
 
Back
Top