本文告诉大家如何通过 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("
");
}
catch (Exception e)
{
Console.WriteLine(temp + " " + e);
}
}
str.Append("
");
}
return str.ToString();
输出 str 的内容
Caption : 坚果云
Description : 坚果云
IdentifyingNumber : {FEA8B01C-3F43-470A-BB28-679B1AEEC6E8}
InstallDate : 20180305
InstallLocation : C:Program FilesNutstore
HelpLink : http://help.jianguoyun.com
HelpTelephone :
InstallSource : C:UserslindeAppDataRoamingNutstoreClientinstallAEEC6E8
Language : 2052
LocalPackage : C:WINDOWSInstaller4acb3a9.msi
Name : 坚果云
PackageCache : C:WINDOWSInstaller4acb3a9.msi
PackageCode : {3802EFD2-0953-4527-835E-E4C459062CD5}
PackageName : Nutstore.x64.msi
ProductID :
RegOwner :
RegCompany :
SKUNumber :
Transforms : C:WINDOWSInstaller{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 FilesAppleApple Application Support
HelpLink : http://www.apple.com/cn/support/
HelpTelephone : (86) 800 810 2323
InstallSource : C:UserslindeAppDataLocalTempIXP246.TMP
Language : 2052
LocalPackage : C:WINDOWSInstaller1a1ef7b.msi
Name : Apple 应用程序支持 (32 位)
PackageCache : C:WINDOWSInstaller1a1ef7b.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
更多 WMI 博客请看
我搭建了自己的博客 https://blog.lindexi.com/ 欢迎大家访问,里面有很多新的博客。只有在我看到博客写成熟之后才会放在csdn或博客园,但是一旦发布了就不再更新
如果在博客看到有任何不懂的,欢迎交流,我搭建了 dotnet 职业技术学院 欢迎大家加入
本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可。欢迎转载、使用、重新发布,但务必保留文章署名林德熙(包含链接:http://blog.csdn.net/lindexi_gd ),不得用于商业目的,基于本文修改后的作品务必以相同的许可发布。如有任何疑问,请与我联系。