WMI:获取已安装软件的列表 [英] WMI: Get the list of Installed Softwares

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

问题描述

我需要使用 wmi 调用获取远程 Windows 主机上已安装软件的列表.我曾尝试使用 Win32_ProductWin32Reg_AddRemovePrograms 类.

I need to get the list of installed softwares on remote Windows hosts using wmi calls. I have tried using Win32_Product and Win32Reg_AddRemovePrograms Classes.

使用 Win32_Product 的好处是,它显示机器上安装的所有软件,但它非常非常慢,并且不能在超过 90% 的主机上运行(给出类似 - NTSTATUS:NT 代码 0xc002001b - NT 代码 0xc002001b).另一方面,Win32Reg_AddRemovePrograms 速度更快,在大多数主机上运行良好,但缺少大量软件.

Advantage of using Win32_Product is that, it displays all the softwares installed on the machine, but it is very very slow and does not work on more than 90% hosts (giving errors like- NTSTATUS: NT code 0xc002001b - NT code 0xc002001b). On the other hand, Win32Reg_AddRemovePrograms is much quicker and works pretty well on most of the hosts, but misses plenty of softwares.

是否还有其他 Win32 类可以有效地执行相同操作?

Is there any other Win32 Class that could do the same efficiently?

推荐答案

你可以使用 wmic.

You can use wmic.

示例:

wmic product get name,version /format:csv

wmic /node:localhost /output:d:\programlist.htm product
get name,version /format:htable.xsl

wmic product get name,version

wmic softwareelement get name,version

wmic softwarefeature get name,version

wmic wmic:root\cli>/output:c:\ProgramList.txt product get name,version

或者您可以像添加/删除程序"一样执行此操作,读取所有卸载注册表项:

Or you can do it like the "Add/Remove Programs", reading all uninstall registry keys:

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall

在 64 位 Windows 上,还记得检查:

On 64 bit Windows, remember to also check:

HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\

要返回计算机上安装的所有软件的列表,无论是否由 Windows 安装程序:

To returns a list of all software installed on a computer, whether or not by Windows-Installer:

Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE 
strComputer = "." 
strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" 
strEntry1a = "DisplayName" 
strEntry1b = "QuietDisplayName" 
strEntry2 = "InstallDate" 
strEntry3 = "VersionMajor" 
strEntry4 = "VersionMinor" 
strEntry5 = "EstimatedSize" 

Set objReg = GetObject("winmgmts://" & strComputer & _ 
 "/root/default:StdRegProv") 
objReg.EnumKey HKLM, strKey, arrSubkeys 
WScript.Echo "Installed Applications" & VbCrLf 
For Each strSubkey In arrSubkeys 
  intRet1 = objReg.GetStringValue(HKLM, strKey & strSubkey, _ 
   strEntry1a, strValue1) 
  If intRet1 <> 0 Then 
    objReg.GetStringValue HKLM, strKey & strSubkey, _ 
     strEntry1b, strValue1 
  End If 
  If strValue1 <> "" Then 
    WScript.Echo VbCrLf & "Display Name: " & strValue1 
  End If 
  objReg.GetStringValue HKLM, strKey & strSubkey, _ 
   strEntry2, strValue2 
  If strValue2 <> "" Then 
    WScript.Echo "Install Date: " & strValue2 
  End If 
  objReg.GetDWORDValue HKLM, strKey & strSubkey, _ 
   strEntry3, intValue3 
  objReg.GetDWORDValue HKLM, strKey & strSubkey, _ 
   strEntry4, intValue4 
  If intValue3 <> "" Then 
     WScript.Echo "Version: " & intValue3 & "." & intValue4 
  End If 
  objReg.GetDWORDValue HKLM, strKey & strSubkey, _ 
   strEntry5, intValue5 
  If intValue5 <> "" Then 
    WScript.Echo "Estimated Size: " & Round(intValue5/1024, 3) & " megabytes" 
  End If 
Next 

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

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