Sasha Chedygov
Sasha Chedygov

Reputation: 130967

How to read installer shortcuts with C# (WPF)

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.

Upvotes: 0

Views: 1419

Answers (2)

Sasha Chedygov
Sasha Chedygov

Reputation: 130967

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.

Upvotes: 1

Daniel Earwicker
Daniel Earwicker

Reputation: 116744

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

Upvotes: 0

Related Questions