views:

513

answers:

2

Background: I've decided to teach myself C# through WPF, and I'm writing a small application that needs to get a list of Start Menu shortcuts and their targets and store them. Basically, I'm trying to take all the shortcuts and put their target applications' paths into memory. However, I've run into a problem trying to read Windows Installer shortcuts (the ones that point to something like C:\Windows\Installer\{90120000-0030-0000-0000-0000000FF1CE}\wordicon.exe -- Microsoft Office is a good example of this). I did some research and it seems that Windows uses some behind-the-scenes magic involving the Registry to find the actual location of the file.


Question: How can I get the actual target of these Windows Installer shortcuts in C#? A lot of sources I've found point me to the IShellLink interface, but I don't know how to use it with C#. I'd prefer to use Windows API calls (or, even better, a .NET library) instead of manually looking through the Registry, but I'll take any guidance on the issue.

A: 

I'm afraid IShellLink IS the Windows API for using shell links! The Shell API is heavily COM-based.

But the good news is that COM interop works very well in .NET. This site is usually a very good resource:

http://www.pinvoke.net/default.aspx/Interfaces/IShellLinkA.html

Daniel Earwicker
Being a C# newbie, the link doesn't really help. What do I do with the interface? I'd also like to understand the problem, so just giving me the interface is fairly useless to me. But thanks anyway.
musicfreak
I'll try and knock up a sample soon.
Daniel Earwicker
A: 

After doing more research, I found an easy answer here. It's basically using a combination of the MsiGetShortcutTarget and MsiGetComponentPath functions of msi.dll.

musicfreak