c# - 获取已安装产品列表c#

标签 c# .net installation registry windows-installer

为了安装/卸载/更新我们的软件,我们的自定义安装程序使用 WindowsInstaller.Installer.Products 从 Windows 注册表获取已安装产品的列表。

在某些客户端计算机上,未知软件可能会向注册表“HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Products”添加一个新条目,其名称类似于“ABCD”。这导致 WindowsInstaller.Installer.Products 引发异常。我可以通过手动将名为“test”的注册表项添加到“HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Products”中来重新创建此场景。如果我将测试重命名为新的 GUID,那么模拟问题就会得到解决。

您能建议任何可能的解决方法/解决方案吗?

使用 MSIINV.exe 工具会很困难,因为它是第 3 方工具,但这似乎有帮助。

最佳答案

我将查看 Windows Installer XML (WiX) 部署工具基础 (DTF) 中的 Microsoft.Deployment.WindowsInstaller 命名空间。它有:

public static IEnumerable<ProductInstallation> GetProducts(
    string productCode,
    string userSid,
    UserContexts context
)

productCode (String)

ProductCode (GUID) of the product instances to be enumerated. Only instances of products within the scope of the context specified by the userSid and context parameters will be enumerated. This parameter may be set to null to enumerate all products in the specified context.

userSid (String)

Specifies a security identifier (SID) that restricts the context of enumeration. A SID value other than s-1-1-0 is considered a user SID and restricts enumeration to the current user or any user in the system. The special SID string s-1-1-0 (Everyone) specifies enumeration across all users in the system. This parameter can be set to null to restrict the enumeration scope to the current user. When context is set to the machine context only, userSid must be null.

context (UserContexts)

Specifies the user context.

它包装了 Win32 MSI API MsiEnumProductsEx 函数。这会返回 ProductInstallation 的集合,您可以对其执行 Linq 查询,以找出您需要了解的有关已安装 MSI 的任何信息。

关于c# - 获取已安装产品列表c#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17274073/

相关文章:

c# - 私有(private)属性(property)的设定值

c# - 泛型类型推断在 C# 中如何工作?

c# - 如何对找到的棋盘角进行排序?

html - 在VB2010中有什么简单的方法可以为单个单词添加颜色?

.net - 使用 SQLExpress 进行多用户商业应用程序的经验?

c# - 如何制作可伪造的事件

c# - DropDownList对于没有 IEnumerable 类型的 ViewData 项

.net - Automapper - 需要区分大小写

IIS 7.0 IIS 管理器没有可用的选项 "Manage Packages"

macos - 解析/usr/sbin/installer 的输出