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

From: Torgeir Bakken \(MVP\) (Torgeir.Bakken-spam_at_hydro.com)
Date: 01/27/05


Date: Fri, 28 Jan 2005 00:43:33 +0100

Liviu Anca wrote:

> 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.
Hi

Looking for the registry value "ParentKeyName" under the
"...Uninstall" key looks like the only way to obtain it.

Here is a script that uses WMI's StdRegProv to do the job:

'--------------------8<----------------------
sComputer = "." ' use . for local computer
sAppsList = UpdatesInARP(sComputer)

For Each sAppName In Split(sAppsList, vbCrLf)
    If sAppName <> "" Then
      WScript.Echo sAppName
    End If
Next

Function UpdatesInARP(node)
   Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
   Set oRegistry = _
         GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
       & node & "/root/default:StdRegProv")
   sBaseKey = _
      "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
   iRC = oRegistry.EnumKey(HKLM, sBaseKey, arSubKeys)
   For Each sKey In arSubKeys
     sValue = ""
     iRC = oRegistry.GetStringValue( _
             HKLM, sBaseKey & sKey, "ParentKeyName", sPKNValue)
     If iRC = 0 Then
       If sPKNValue <> "" Then
         iRC = oRegistry.GetStringValue( _
                  HKLM, sBaseKey & sKey, "DisplayName", sValue)
         If iRC <> 0 Then
           oRegistry.GetStringValue _
               HKLM, sBaseKey & sKey, "QuietDisplayName", sValue
         End If
       End If
     End If
     If sValue <> "" Then
       UpdatesInARP = _
           UpdatesInARP & sValue & vbCrLf
     End If
   Next
End Function
'--------------------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

  • Re: Links bar missing, other weird errors
    ... afraid I have a much more serious problem than a registry ... >Have you tried un-locking the toolbars and seeing if you ... >Scripting enabled. ... >the Security tab. ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: Test for existing registry value?
    ... >> registry value exists. ... > torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway ...
    (microsoft.public.scripting.wsh)
  • Re: script registry editing
    ... > of remote machines. ... WMI and it's StdRegProv class: ... Documentation in regobj.doc and a remote registry example in registry.vbs ... -- torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway Administration scripting examples and an ONLINE version of the 1328 page Scripting Guide: ...
    (microsoft.public.windows.server.scripting)
  • Re: Cant read values from HKEY_USERS
    ... > SID's from the registry. ... Note that for Win2k SP4, ... Cannot Use WMI to Query HKEY Users After You Install SP4 ... -- torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway Administration scripting examples and an ONLINE version of the 1328 page Scripting Guide: ...
    (microsoft.public.win2000.registry)
  • Re: StdRegProv and GetExpandedStringValue
    ... > registry, not the local one, and have the variable not expanded. ... and doesn't expand the value data. ... Microsoft MVP Scripting and WMI, ...
    (microsoft.public.windowsxp.wmi)