简体   繁体   English

如何使用C#(WPF)阅读安装程序快捷方式

[英]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. 背景:我决定通过WPF自学C#,并且我正在编写一个小应用程序,该应用程序需要获取“开始菜单”快捷方式及其目标的列表并进行存储。 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). 但是,尝试读取Windows Installer快捷方式(指向类似C:\\Windows\\Installer\\{90120000-0030-0000-0000-0000000FF1CE}\\wordicon.exe快捷方式时遇到了问题– Microsoft Office是一个很好的例子)。 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. 我进行了一些研究,似乎Windows使用了一些涉及注册表的后台魔术来查找文件的实际位置。


Question: How can I get the actual target of these Windows Installer shortcuts in C#? 问题:如何在C#中获取这些Windows Installer快捷方式的实际目标? A lot of sources I've found point me to the IShellLink interface, but I don't know how to use it with C#. 我发现了很多资源,它们指向IShellLink接口,但是我不知道如何在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. 我宁愿使用Windows API调用(或者更好的是使用.NET库),而不是手动查看注册表,但是我会在此问题上提供任何指导。

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 . 它基本上使用的组合MsiGetShortcutTargetMsiGetComponentPath的功能msi.dll

I'm afraid IShellLink IS the Windows API for using shell links! 恐怕IShellLink是使用Shell链接的Windows API! The Shell API is heavily COM-based. Shell API很大程度上基于COM。

But the good news is that COM interop works very well in .NET. 但是好消息是COM互操作在.NET中工作得很好。 This site is usually a very good resource: 该站点通常是非常好的资源:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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