检索已安装服务的 MSI 产品代码 [英] Retrieve MSI product code for an installed Service

查看:31
本文介绍了检索已安装服务的 MSI 产品代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经四处寻找答案,希望我的google-fu"不是问题......无论如何.

I've looked around a fair amount for an answer to this, hopefully my "google-fu" is not the issue...anyhow.

我想枚举 Windows(2003 R2、2008、2008 R2)机器上的所有服务,然后确定它们的产品代码是什么,以确定用于安装该 Windows 服务的 MSI 包(在我们维护的存储库中).

I want to enumerate all the services on a Windows (2003 R2, 2008, 2008 R2) machine and then determine what their product codes are to determine what MSI Package (in our maintained repository) was used to install that Windows Service).

基本上,从类似于此 PS 命令的内容中获取列表:{Get-Service |Format-List *} 或 C# 行:System.ServiceProcess.ServiceController[] services = ServiceController.GetServices();,然后遍历所有返回的服务名称并确定每个服务的 MSI 产品代码.

Basically, take the list that comes from something like this PS command: {Get-Service | Format-List *}, or the C# line: System.ServiceProcess.ServiceController[] services = ServiceController.GetServices();, and then iterate over all those returned service names and determine what the MSI Product Code is for each.

我更喜欢 C# 路线,但会采纳所有建议.

I'd prefer the C# route, but will take all suggestions.

这可能吗?或者在我的示例中是否有不涉及 ServiceController 类的更好方法?

Is this possible? Or is there a better way that does not involve the ServiceController class in my example?

提前感谢您的建议!

推荐答案

WiX DTF 的 Microsoft.Deployment.WindowsInstaller 有一个名为 ComponentInstallation 的类.它有一个名为 AllComponents 的静态属性,它返回一个 ComponentInstallation 的 IEnumerable.

WiX DTF's Microsoft.Deployment.WindowsInstaller has a class called ComponentInstallation. It has a static property called AllComponents that returns an IEnumerable of ComponentInstallation.

我想您可以查询 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services 以获取图像路径并尝试将其与 MSI 管理的组件相关联.建立该连接后,ComponentInstallation 类具有一个名为 ClientProducts 的属性,该属性返回 ProductInstallation 的 IEnumerable.请记住,一个组件可以在多个 MSI 之间共享.

I suppose you could query HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services to get the imagepath and try to correlate it to a Component that is managed by MSI. Once you make that connection the ComponentInstallation class has a property called ClientProducts that returns IEnumerable of ProductInstallation. Remember, a component can be shared across multiple MSI's.

获得 ProductInstallation 引用后,您可以获得它的 ProductCode 属性.

Once you have the ProductInstallation reference you can get it's ProductCode property.

这会捕获 MSI 安装的服务,即使它们正在使用 InstallUtil,因为您正在跟踪谁放置了文件.

This would catch the services that were installed by MSI even if they were using InstallUtil because you are tracking who laid down the file.

这篇关于检索已安装服务的 MSI 产品代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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