Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

windows - WMI: Get the list of Installed Softwares

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.

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.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use wmic.

Example:

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:rootcli>/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_MACHINESoftwareMicrosoftWindowsCurrentVersionUninstall

On 64 bit Windows, remember to also check:

HKLMSOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall

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 = "SOFTWAREMicrosoftWindowsCurrentVersionUninstall" 
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 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...