本文告诉大家如何通过 WMI 获取系统安装的软件,这个方法不能获取全部的软件
通过 Win32_Product 可以获取系统安装的软件
var mc = "Win32_Product";
var managementObject = new[]
{
"Caption",
"Description",
"IdentifyingNumber",
"InstallDate",
"InstallLocation",
"HelpLink",
"HelpTelephone",
"InstallSource",
"Language",
"LocalPackage",
"Name",
"PackageCache",
"PackageCode",
"PackageName",
"ProductID",
"RegOwner",
"RegCompany",
"SKUNumber",
"Transforms",
"URLInfoAbout",
"URLUpdateInfo",
"Vendor",
"WordCount",
"Version",
};
ManagementClass managementClass = new ManagementClass(mc);
ManagementObjectCollection managementObjectCollection = managementClass.GetInstances();
var str = new StringBuilder();
foreach (ManagementObject m in managementObjectCollection)
{
foreach (var temp in managementObject)
{
try
{
str.Append(temp);
str.Append(" ");
str.Append(m[temp]?.ToString() ?? "");
str.Append("\n");
}
catch (Exception e)
{
Console.WriteLine(temp + " " + e);
}
}
str.Append("\n");
}
return str.ToString();
输出 str 的内容
Caption : 坚果云
Description : 坚果云
IdentifyingNumber : {FEA8B01C-3F43-470A-BB28-679B1AEEC6E8}
InstallDate : 20180305
InstallLocation : C:\Program Files\Nutstore\
HelpLink : http://help.jianguoyun.com
HelpTelephone :
InstallSource : C:\Users\linde\AppData\Roaming\NutstoreClient\install\AEEC6E8\
Language : 2052
LocalPackage : C:\WINDOWS\Installer\4acb3a9.msi
Name : 坚果云
PackageCache : C:\WINDOWS\Installer\4acb3a9.msi
PackageCode : {3802EFD2-0953-4527-835E-E4C459062CD5}
PackageName : Nutstore.x64.msi
ProductID :
RegOwner :
RegCompany :
SKUNumber :
Transforms : C:\WINDOWS\Installer\{FEA8B01C-3F43-470A-BB28-679B1AEEC6E8}\Nutstore.mst
URLInfoAbout : https://www.jianguoyun.com/
URLUpdateInfo :
Vendor : 上海亦存网络科技有限公司
WordCount : 0
Version : 4.0.8
Caption : Apple 应用程序支持 (32 位)
Description : Apple 应用程序支持 (32 位)
IdentifyingNumber : {5A659BE5-849B-484E-A83B-DCB78407F3A4}
InstallDate : 20190221
InstallLocation : C:\Program Files (x86)\Common Files\Apple\Apple Application Support
HelpLink : http://www.apple.com/cn/support/
HelpTelephone : (86) 800 810 2323
InstallSource : C:\Users\linde\AppData\Local\Temp\IXP246.TMP\
Language : 2052
LocalPackage : C:\WINDOWS\Installer\1a1ef7b.msi
Name : Apple 应用程序支持 (32 位)
PackageCache : C:\WINDOWS\Installer\1a1ef7b.msi
PackageCode : {F3D0B996-B6DB-4283-9565-004518A6610B}
PackageName : AppleApplicationSupport.msi
ProductID :
RegOwner :
RegCompany :
SKUNumber :
Transforms :
URLInfoAbout : http://www.apple.com/cn/
URLUpdateInfo : http://www.apple.com/cn/
Vendor : Apple Inc.
WordCount : 0
Version : 7.3
本文会经常更新,请阅读原文: https://lindexi.gitee.io/post/dotnet-%E9%80%9A%E8%BF%87-WMI-%E8%8E%B7%E5%8F%96%E7%B3%BB%E7%BB%9F%E5%AE%89%E8%A3%85%E8%BD%AF%E4%BB%B6.html ,以避免陈旧错误知识的误导,同时有更好的阅读体验。
本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可。欢迎转载、使用、重新发布,但务必保留文章署名林德熙(包含链接: https://lindexi.gitee.io ),不得用于商业目的,基于本文修改后的作品务必以相同的许可发布。如有任何疑问,请 与我联系 。