简体   繁体   中英

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.

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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM