views:

343

answers:

3

Is it possible to find out the service packs that are installed on a Windows 2000 machine using WMI?

+1  A: 

There's a suggested way of getting installed software using WMI - although not all software shows up, so you'd have to...

1) Try it out and see if they appear at all

2) Adjust the example to filter the results so only service packs show

strHost = "."
Const HKLM = &H80000002
Set objReg = GetObject("winmgmts://" & strHost & _
    "/root/default:StdRegProv")
Const strBaseKey = _
    "Software\Microsoft\Windows\CurrentVersion\Uninstall\"
objReg.EnumKey HKLM, strBaseKey, arrSubKeys
For Each strSubKey In arrSubKeys
    intRet = objReg.GetStringValue(HKLM, strBaseKey & strSubKey, _
        "DisplayName", strValue)
    If intRet <> 0 Then
        intRet = objReg.GetStringValue(HKLM, strBaseKey & strSubKey, _
        "QuietDisplayName", strValue)
    End If
    If (strValue <> "") and (intRet = 0) Then
        WScript.Echo strValue
    End If
Next
Sohnee
A: 

Yes, the wmi class Win32_OperatingSystem contains all of this information. I can see verify this information by using powershell to check my local machine:

PS c:\> get-wmiobject win32_operatingsystem | `
            select BuildNumber, ServicePackMajorVersion, `
            ServicePackMinorVersion | format-table -auto

BuildNumber ServicePackMajorVersion ServicePackMinorVersion
----------- ----------------------- -----------------------
7100                              0                       0

Note: Powershell only runs on XP or higher, but you can check remote systems by passing a -Computer parameter to get-wmiobject.

x0n
A: 

A VBScript example from Hey, Scripting Guy! series:

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colOperatingSystems = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")

For Each objOperatingSystem in colOperatingSystems
    Wscript.Echo objOperatingSystem.ServicePackMajorVersion  _
        & "." & objOperatingSystem.ServicePackMinorVersion
Next
Helen