获取列出已安装的产品的C# [英] Getting List Of Installed Products c#

查看:151
本文介绍了获取列出已安装的产品的C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

和一些客户机,一个不知名的软件可能是添加新条目添加到注册表 HKEY_LOCAL_MACHINE \ SOFTWARE \ Classes下\安装\产品一个名为类似ABCD的关键。这是造成 WindowsInstaller.Installer.Products 来抛出异常。我可以再通过手动添加注册表项,进入 HKEY_LOCAL_MACHINE \ SOFTWARE \ Classes下\安装\产品命名为测试创建这种情况下。如果我重新命名测试一个新的GUID,然后模拟问题得到解决。

您可以提出任何可能的解决方法/解决方案?

使用MSIINV.exe工具将是困难的,因为这是一个第三方工具,但似乎帮助。

解决方案

我想看看在Windows安装器XML(WiX的)部署工具基金会(DTF)发现Microsoft.Deployment.WindowsInstaller命名空间。它有:

 公共静态的IEnumerable< ProductInstallation>的GetProducts(
    串产品code,
    串userSid,
    UserContexts背景
)
 

  

产品code(字符串)

     该产品实例

产品code(GUID)是   枚举。产品的上下文的范围内唯一的实例   由userSid和环境参数中指定将被枚举。   该参数可以设置为null以枚举所有的产品在   指定的范围内。

     

userSid(字符串)

     

指定一个安全标识符   (SID)限制枚举的上下文中。一个SID值等   比S-1-1-0被认为是一个用户的SID和限制枚举的   当前用户或系统中的任何用户。特殊的SID字符串s-1-1-0   (每个人)指定系统中的所有用户枚举。本   参数可以设置为null以限制枚举范围的   当前用户。当上下文设置为机器上下文只,userSid   必须为空。

     

上下文(UserContexts)

     

指定用户上下文

这是包装在Win32 API的MSI功能MsiEnumProductsEx。此带回ProductInstallation,你可以做LINQ查询对,找出任何你需要知道的关于安装微星的集合。

To Install/Uninstall/Update our software, our custom installer uses WindowsInstaller.Installer.Products to get the list of installed products from windows registry.

And on some client machines, an unknown software is probably adding a new entry to the registry 'HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Products' a key with name something like 'ABCD'. This is causing WindowsInstaller.Installer.Products to throw an exception. I can re create this scenario by manually adding a registry key entry into 'HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Products' named 'test'. And if I rename test to a new GUID then the simulated problem gets solved.

Can you suggest any possible workaround/solution?

Using MSIINV.exe tool would be difficult, as that is a 3rd party tool, but that seems to help.

解决方案

I'd take a look at the Microsoft.Deployment.WindowsInstaller namespace found in Windows Installer XML (WiX) Deployment Tools Foundation (DTF). It has:

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.

that wraps the Win32 MSI API MsiEnumProductsEx function. This brings back a collection of ProductInstallation that you can do Linq queries against to find out anything you need to know about installed MSI's.

这篇关于获取列出已安装的产品的C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆