Re: How to retrieve "software updates" with WMI ?

From: Liviu Anca (aliviu_at_hotmail.com)
Date: 01/27/05


Date: Thu, 27 Jan 2005 10:38:37 +0200

Hi Torgeir,

Thank you for your detailed reply. However, this is not what I meant. Maybe
I was not clear enough, I try now to be more specific. Here are the steps:

- installed WinXP with SP1 (with Windows Media Player 8 included)
- updated Windows Media Player (to version 10) through WindowsUpdate site
- installed SP2

In this situation, when "Show updates" is checked in Add/Remove Programs, I
am able to see under "Windows Updates" the following items:
- Windows Media Player 10
- Windows Media Format Runtime

Please let me know if it is possible to retrieve this information using WMI
and which class should I use. Win32_Product and Win32_QuickFixEngineering do
not seem useful here.
I know that an alternative way may be to directly read from registry under
"...Uninstall" key, but I'm trying to get to a WMI solution now.

Liviu Anca [MCSD]

"Torgeir Bakken (MVP)" <Torgeir.Bakken-spam@hydro.com> wrote in message
news:%23vj0Qb7AFHA.3592@TK2MSFTNGP11.phx.gbl...
> eu wrote:
>
> > With SP2 for Windows XP, there is a new checkbox "Show updates" in
> > Add/Remove Programs. How may I retrieve these updates with WMI ?
> > I can enumerate successfully the installed software using WMI class
> > Win32_Product, but not those updates.
> Hi
>
> The VBScript below will list updates installed regardless if Windows
> Update history exist or not, and if data exists, also the description,
> the user that installed it and installation date.
>
> The updates listing is obtained through the WMI class
> Win32_QuickFixEngineering.
>
> Put it in a text file and save it as e.g. ListHotfixes.vbs, to run it,
> double click on it or start it like this:
>
> wscript.exe "C:\Scripts\ListHotfixes.vbs"
>
> (assuming you have put the script in the folder C:\Scripts\)
>
>
> The VBScript will give this type of output:
>
> ------------------------------------------
>
> Hotfix report date: 2004-10-19 18:01:19
>
> OS version: Microsoft Windows XP Professional
> SP version: Service Pack 2
> OS language: English
>
> Hotfixes Identified:
>
> HotFixID: Q282784
> Description: Windows XP Hotfix (SP1) [See Q282784 for more information]
> InstalledBy:
> InstallDate: (none found)
>
> HotFixID: Q282784
> Description: Windows XP Hotfix (SP1) [See Q282784 for more information]
> InstalledBy: Usr123456
> InstallDate: 10/18/2004
>
> ...
>
> ------------------------------------------
>
>
> Script start:
>
>
> '--------------------8<----------------------
> '
> ' Description: Script that outputs some computer information
> ' and lists all installed hotfixes including installation date
> '
> ' For Windows 2000 SP3/SP4, Windows XP (all versions) and
> ' Windows 2003 Server (all versions)
> '
> ' Author: Torgeir Bakken
> ' Date: 2004-10-19
> '
> ' Revisions
> ' 2004-12-09: Added support for the new IE update structure in registry
> '
>
> Const OpenAsASCII = 0
> Const OverwriteIfExist = -1
>
> Set oShell = CreateObject("WScript.Shell")
> Set oFSO = CreateObject("Scripting.FileSystemObject")
>
> sFile = oFSO.GetSpecialFolder(2).ShortPath & "\updates.txt"
> Set fFile = oFSO.CreateTextFile(sFile, OverwriteIfExist, OpenAsASCII)
>
> fFile.WriteLine
> fFile.WriteLine "Hotfix report date: " & Now & vbCrLf
>
> strComputer = "." ' use "." for local computer
>
> Const HKLM = &H80000002
>
> 'On Error Resume Next
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")
>
> Set colSettings = objWMIService.ExecQuery _
> ("Select * from Win32_OperatingSystem")
>
> ' get general info about the OS
>
> ' Caption value for different OS:
> ' Microsoft Windows 2000 ...
> ' Microsoft Windows XP ...
> ' Microsoft(R) Windows(R) Server 2003, ..... Edition
> For Each objOperatingSystem in colSettings
> strOSCaption = objOperatingSystem.Caption
> Select Case True
> Case InStr(1, strOSCaption, "windows 2000", vbTextCompare) > 0
> strOS = "Windows 2000"
> Case InStr(1, strOSCaption, "windows xp", vbTextCompare) > 0
> strOS = "Windows XP"
> Case InStr(1, strOSCaption, "windows(r) server 2003", vbTextCompare)
> 0
> strOS = "Windows Server 2003"
> End Select
>
> intOSLang = objOperatingSystem.OSLanguage
> strOSLangHex = Right("000" & Hex(intOSLang), 4)
> strOSServicePack = objOperatingSystem.CSDVersion
> Next
>
> Set objReg = GetObject("WinMgmts:{impersonationLevel=impersonate}!//" _
> & strComputer & "/root/default:StdRegProv")
>
> strOSLanguage = "Unknown" ' Init value
> strKeyPath = "SOFTWARE\Classes\MIME\Database\Rfc1766"
> strValueName = strOSLangHex
> objReg.GetStringValue HKLM, strKeyPath, strValueName, strOSLanguage
>
> ' remove unnecessary stuff
> arrOSLanguage = Split(strOSLanguage, ";")
> strOSLanguage = arrOSLanguage(UBound(arrOSLanguage))
> If Instr(strOSLanguage, "(") > 0 Then
> arrOSLanguage = Split(strOSLanguage, "(")
> strOSLanguage = Trim(arrOSLanguage(0))
> End If
>
> fFile.WriteLine "OS version: " & strOSCaption
> fFile.WriteLine "SP version: " & strOSServicePack
> fFile.WriteLine "OS language: " & strOSLanguage
>
> ' start enumeration of hotfixes
>
> fFile.WriteLine vbCrLf & "Hotfixes Identified:" & vbCrLf
>
> strRegBaseUpdOS = "SOFTWARE\Microsoft\Updates\" & strOS
> strRegBaseUpdIE = "SOFTWARE\Microsoft\Updates\Internet Explorer 6\SP1\"
>
> Set colItems = objWMIService.ExecQuery _
> ("Select * from Win32_QuickFixEngineering",,48)
>
> For Each objItem in colItems
> If objItem.HotFixID <> "File 1" Then
> fFile.WriteLine "HotFixID: " & objItem.HotFixID
> fFile.WriteLine "Description: " & objItem.Description
> fFile.WriteLine "InstalledBy: " & objItem.InstalledBy
> strInstallDate = Null ' init value
>
> If InStr(1, objItem.HotFixID, "-IE6SP1-", vbTextCompare) > 0 Then
> strRegKey = strRegBaseUpdIE & objItem.HotFixID
> objReg.GetStringValue HKLM, strRegKey, _
> "InstalledDate", strInstallDate
> ElseIf objItem.ServicePackInEffect <> "" Then
> strRegKey = strRegBaseUpdOS & "\" & objItem.ServicePackInEffect _
> & "\" & objItem.HotFixID
> objReg.GetStringValue HKLM, strRegKey, _
> "InstalledDate", strInstallDate
> End If
>
> If IsNull(strInstallDate) Then
> strInstallDate = "(none found)"
> End If
> fFile.WriteLine "InstallDate: " & strInstallDate
> fFile.WriteLine ' blank line
> End If
> Next
>
> fFile.Close
> oShell.Run sFile
>
> '--------------------8<----------------------
>
>
>
> --
> torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
> Administration scripting examples and an ONLINE version of
> the 1328 page Scripting Guide:
> http://www.microsoft.com/technet/scriptcenter/default.mspx



Relevant Pages

  • How to use scripting to secure your Win2K network--some examples
    ... Software Installation script: ... The purpose of this script is to ... Let's see how service packs and hotfixes are handled in the script: ... NT4 in the way the local system account accesses network resources. ...
    (NT-Bugtraq)
  • HFDeploy [laenglich!] (was: Patchen)
    ... Setup information file for Windows 2000 HotFixes. ... Dateien das Attribut "hidden". ... anzuhaengenden Zeilen (bei Installation direkt von CD eigentlich ...
    (microsoft.public.de.security.netzwerk.sicherheit)
  • Re: Visual Studio 2008 C# editor suddenly very slow
    ... Make sure that you have installed the latest updates for both VS and Windows ... There are three other hotfixes but these are probably not related to your ... The laptop contains a brand new Windows Vista ... installation and Visual Studio Team System 2008 (Version 9.0.21022.8 ...
    (microsoft.public.vstudio.development)
  • Re: deploy security patch in a login script
    ... > I want to deploy the MS03-039 patch by login script. ... > without the users having to click through the buttons on the installation ... ' Windows 95: 1 ...
    (microsoft.public.windows.server.scripting)
  • Re: windows updates list
    ... I suppose the Add/Remove programs applet lists service packs ... The VBScript below will list updates installed regardless if Windows ... the user that installed it and installation date. ... Hotfixes Identified: ...
    (microsoft.public.win2000.general)