Re: WUA API

152 views
Skip to first unread message

maximillianx

unread,
Jul 8, 2005, 12:08:26 PM7/8/05
to
You'd want to post in here:
news:microsoft.public.windows.server.update_services or possibly a .Net
group...
I'd like to see some information on this as well, but I'd like to see some
VBScript implementation. Please let me know if you find anything!
Rob
<Rik> wrote in message news:e2A8dx5g...@TK2MSFTNGP10.phx.gbl...
> Hi,
>
> Is this the right group to post questions related to the WUA API?


Torgeir Bakken (MVP)

unread,
Jul 8, 2005, 1:19:21 PM7/8/05
to
maximillianx wrote:

> You'd want to post in here:
> news:microsoft.public.windows.server.update_services or possibly a .Net
> group...
> I'd like to see some information on this as well, but I'd like to see some
> VBScript implementation. Please let me know if you find anything!

Hi,

Below are what I know of VBScript examples that uses the Windows
Update Agent API that is documented here:
http://msdn.microsoft.com/library/en-us/wua_sdk/wua/portal_client.asp

Several VBScript examples available at the MSDN web site:

Using the Windows Update Agent API
http://msdn.microsoft.com/library/en-us/wua_sdk/wua/using_the_windows_update_agent_api.asp


Other examples:

"View Installation History" for WU5 without using the WU Web site
http://groups.google.co.uk/group/microsoft.public.windowsupdate/msg/dee85221176110ad?dmode=source&hl=en

A modified version that gets a report that only contains the log entries
that contains successfully installed updates:
http://groups.google.co.uk/group/microsoft.public.windowsxp.general/msg/c4121dbbc0f593fd?dmode=source&hl=en


A VBScript that finds updates that are hidden, and un-hides them:

'--------------------8<----------------------

On Error Resume Next
Dim oSearcher, oSearchResult, i, oUpdate

Set oSearcher = CreateObject("Microsoft.Update.Searcher")

' use locally cached information
oSearcher.Online = False

' find updates that are hidden
Set oSearchResult = oSearcher.Search("IsHidden=1")

If Err.Number = 0 Then
If oSearchResult.Updates.Count > 0 Then
For i = 0 to oSearchResult.Updates.Count - 1
Set oUpdate = oSearchResult.Updates(i)
' unhide the update
oUpdate.IsHidden = False
Next
End If
End If

'--------------------8<----------------------

Sample script to check client's update status when the client is using
a WSUS server:

'--------------------8<----------------------

On Error Resume Next
Dim oSearcher, oSearchResult, I, oUpdate

Set oSearcher = CreateObject("Microsoft.Update.Searcher")

' (default) -- talk to the server rather than using locally cached
' information
oSearcher.Online = True

' ssManagedServer -- talk to the WSUS server only
oSearcher.ServerSelection = 1

' this should catch the updates the AU client cares
' about for the WSUS server
Set oSearchResult = oSearcher.Search("DeploymentAction='Installation'" _
& " and IsAssigned=1 and IsInstalled=0 or DeploymentAction=" _
& "'Uninstallation' and IsAssigned=1 and IsPresent=1 or" _
& " DeploymentAction='Installation' and IsAssigned=1 and" _
& " RebootRequired=1 or DeploymentAction='Uninstallation' and" _
& " IsAssigned=1 and RebootRequired=1")

If Err.Number <> 0 Then
WScript.echo "Detection failed"
WScript.quit
End If

If oSearchResult.Updates.Count = 0 Then
WScript.echo "Your computer is up-to-date with the WSUS server"
WScript.quit
End If

For i = 0 to oSearchResult.Updates.Count - 1
Set oUpdate = oSearchResult.Updates(i)
If ((oUpdate.DeploymentAction = 1 And Not oUpdate.IsInstalled) Or _
(oUpdate.DeploymentAction = 2 And oUpdate.IsPresent)) Then
WScript.echo "Some updates are still available to your computer."
WScript.quit
End If
Next

For i = 0 to oSearchResult.Updates.Count - 1
Set oUpdate = oSearchResult.Updates(i)
If oUpdate.RebootRequired Then
WScript.echo "Some updates have been (un)installed on your" _
& " computer. Your computer needs to be restarted to computer" _
& " their (un)installation."
WScript.quit
End If
Next

'--------------------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

maximillianx

unread,
Jul 8, 2005, 3:43:10 PM7/8/05
to
Hey Torgeir, yeah, I was aware of the MS pages, but I wasn't sure if there
were other scripts that pulled data from the server side, similar to the VB
API's, but I'm not familiar enough with VB to translate it over to VBScript.

A couple things that I would like to do with the API's:
Find out which exe on my WSUS repository corresponds to a certain update
(KBxxxxx =
\\WSUSServer\d$\wsus\WsusContent\0B\937ADE5183FBF6D46BECEB0C5C249475817B6F0B.exe)
for example

Be able to produce a quick report on a certain computer which updates it has
installed/needed.

Create a historical database for my own reporting of the above report.

It seems the API is a bit under documented with what it could do in
VBScript, but this might just be my ignorance of VB - - there have been some
references in the VB projects that I can't seem to get to work in the
VBScript world - like "microsoft.updateservices.administration".

Do you have any advice for getting something like this to work?

Thanks again, Torgier - you are one smart character :)

Rob

"Torgeir Bakken (MVP)" <Torgeir.B...@hydro.com> wrote in message
news:uelLBH%23gFH...@TK2MSFTNGP09.phx.gbl...

Torgeir Bakken (MVP)

unread,
Jul 8, 2005, 4:51:05 PM7/8/05
to
maximillianx wrote:

> Hey Torgeir, yeah, I was aware of the MS pages, but I wasn't sure if there
> were other scripts that pulled data from the server side, similar to the VB
> API's, but I'm not familiar enough with VB to translate it over to VBScript.
>
> A couple things that I would like to do with the API's:
> Find out which exe on my WSUS repository corresponds to a certain update
> (KBxxxxx =
> \\WSUSServer\d$\wsus\WsusContent\0B\937ADE5183FBF6D46BECEB0C5C249475817B6F0B.exe)
> for example
>
> Be able to produce a quick report on a certain computer which updates it has
> installed/needed.
>
> Create a historical database for my own reporting of the above report.
>
> It seems the API is a bit under documented with what it could do in
> VBScript, but this might just be my ignorance of VB - - there have been some
> references in the VB projects that I can't seem to get to work in the
> VBScript world - like "microsoft.updateservices.administration".
>
> Do you have any advice for getting something like this to work?
>
> Thanks again, Torgier - you are one smart character :)

Hi,

Sorry, for the Windows Server Update Services API there is no COM
interface, so you cannot use VBScript for that interface. You will
need to use a .Net based programming language (e.g. VB.Net or C#).

maximillianx

unread,
Jul 8, 2005, 5:02:00 PM7/8/05
to
Ah - thank you, this answers my question . . . seems I would have been
better off searching for the holy grail, eh?

This is good information to know, now I have to learn .Net!

Rob
"Torgeir Bakken (MVP)" <Torgeir.B...@hydro.com> wrote in message

news:OKRqW9$gFHA...@tk2msftngp13.phx.gbl...

maximillianx

unread,
Jul 8, 2005, 5:57:48 PM7/8/05
to
Torgeir -

Do you know how to return the SUS server value via the api? I guess I could
just as easily pull it from the registry, but figured if I was binding to
the object already, I might as well take the opportunity to pull as much
info from it as I can...

Here's a script that I modified from Microsoft (using the infamous HTML
status code that I've been using for VBSHF):

It downloads the updates, then prompts the user for installation.

----------------------------------------------

'below variables for progress indicators
Dim objShell, objProcessEnv, objSystemEnv, objNet, objFso, objSwitches
Dim query, item, acounter, blnExtendedWMI, blnProcessEvents
Dim dlgBarWidth, dlgBarHeight, dlgBarTop, dlgBarLeft, dlgProgBarWidth,
dlgProgBarHeight
Dim dlgProgBarTop, dlgProgBarLeft
Dim dlgBar, dlgProgBar, wdBar, objPBar, objBar, blnSearchWildcard
Dim blnProgressMode, blnDebugMode, dbgTitle
Dim dbgToolBar, dbgStatusBar, dbgResizable
Dim IE, objDIV, objDBG, strMyDocPath, strSubFolder, strTempFile, f1, ts,
File2Load, objFlash
Dim ws
On Error GoTo 0
Dim dbgWidth, dbgHeight, dbgLeft, dbgTop, dbgVisible
'above variables for progress indicators
''''

fstyle = "tahoma,arial,verdana"
bgcolor1 = "aliceblue"
fformat = "<font face='" & fstyle & "'>"

'set some IE status indicator variables...
blnDebugMode = True
blnProcessEvents = True
blnSearchWildcard = False
blnProgressMode = True

Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshSysEnv = WshShell.Environment("PROCESS")
Set ws = wscript.CreateObject("Scripting.FileSystemObject")
Set updateSession = CreateObject("Microsoft.Update.Session")
Set updateSearcher = updateSession.CreateupdateSearcher()
Set searchResult = updateSearcher.Search("IsInstalled=0 and
Type='Software'")

'ssManagedServer


Call IEStatus
strMsg = "List of applicable items on the machine: <br>"
objdiv.innerhtml = strMsg

For I = 0 To searchResult.Updates.Count-1
Set update = searchResult.Updates.Item(I)
strSearchResultUpdates = strSearchResultUpdates & update.Title & "<br>"

Next
objdiv.innerhtml = strMsg & strsearchResultUpdates

If searchResult.Updates.Count = 0 Then
objdiv.innerhtml = strMsg & fformat & "There are no further updates needed
for your PC at this time."
WScript.Quit
End If

'WScript.Echo vbCRLF & "Creating collection of updates to download:"

Set updatesToDownload = CreateObject("Microsoft.Update.UpdateColl")

For I = 0 to searchResult.Updates.Count-1
Set update = searchResult.Updates.Item(I)
strUpdates = strUpdates & update.Title & "<br>"
updatesToDownload.Add(update)
Next
objdiv.innerhtml = ""
objdiv.innerhtml = fformat & "This PC requires updates from the configured
Update Server. " _
& "<br><br> Downloading needed updates..."

Set downloader = updateSession.CreateUpdateDownloader()
downloader.Updates = updatesToDownload
downloader.Download()

strUpdates = ""
strMsg = ""
objdiv.innerhtml = ""
strMsg = fformat & "List of downloaded updates: <br><br>"
objdiv.innerhtml = strMsg

For I = 0 To searchResult.Updates.Count-1
Set update = searchResult.Updates.Item(I)
If update.IsDownloaded Then
strDownloadedUpdates = strDownloadedUpdates & update.Title & "<br>"
End If
objdiv.innerhtml = strMsg & strDownloadedUpdates
Next

Set updatesToInstall = CreateObject("Microsoft.Update.UpdateColl")

strUpdates = ""
strMsg = ""
objdiv.innerhtml = ""
strMsg = fformat & "Creating collection of downloaded updates to
install:<br><br>"
objdiv.innerhtml = strMsg

For I = 0 To searchResult.Updates.Count-1
set update = searchResult.Updates.Item(I)
If update.IsDownloaded = true Then
strUpdates = strUpdates & update.Title & "<br>"
updatesToInstall.Add(update)
End If
objdiv.innerhtml = strMsg & strUpdates
Next

strResult = MsgBox("Would you like to install updates now?",36,"Install
now?")
strUpdates = ""
strMsg = ""
objdiv.innerhtml = ""
If strResult = 7 Then
WScript.Quit
Else
strMsg = fformat & "Installing updates... <br><br>"
objdiv.innerhtml = strMsg
Set installer = updateSession.CreateUpdateInstaller()
installer.Updates = updatesToInstall
Set installationResult = installer.Install()

'Output results of install
strMsg = fformat & "Installation Result: " & installationResult.ResultCode
& "<br><br>" _
& "Reboot Required: " & installationResult.RebootRequired & "<br><br>" _
& "Listing of updates installed and individual installation results: <br>"
For I = 0 to updatesToInstall.Count - 1
If installationResult.GetUpdateResult(i).ResultCode = 2 Then
strResult = "Installed"
ElseIf installationResult.GetUpdateResult(i).ResultCode = 1 Then
strResult = "In progress"
ElseIf installationResult.GetUpdateResult(i).ResultCode = 3 Then
strResult = "Operation complete, but with errors"
ElseIf installationResult.GetUpdateResult(i).ResultCode = 4 Then
strResult = "Operation failed"
ElseIf installationResult.GetUpdateResult(i).ResultCode = 5 Then
strResult = "Operation aborted"
End If
strUpdates = strupdates & updatesToInstall.Item(i).Title & _
": " & strResult & "<br>"

Next
objdiv.innerhtml = strMsg & strUpdates
End If


'-----------------------------------------------------------
'Function IE Status
'-----------------------------------------------------------
Function IEStatus

'added by Rob - IE status indicator code
If blnProgressMode Then
If blnDebugMode Then
dbgTitle = "Windows Update Script"
Else
dbgTitle = "Windows Update Script"
End If
dbgToolBar = False
dbgStatusBar = False
If blnDebugMode Then
dbgResizable = True
Else
dbgResizable = False
End If
dbgWidth = 500
dbgHeight = 320
dbgLeft = 0
dbgTop = 0
dbgVisible = True
dlgBarWidth = 380
dlgBarHeight = 23
dlgBarTop = 80
dlgBarLeft = 50
dlgProgBarWidth = 0
dlgProgBarHeight = 18
dlgProgBarTop = 82
dlgProgBarLeft = 50
dlgBar = "left: " & dlgBarLeft & "; top: " & dlgBarTop & "; width: " &
dlgBarWidth _
& "; height: " & dlgBarHeight & ";"
dlgProgBar = "left: " & dlgProgBarLeft & "; top: " & dlgProgBarTop & ";
width: " _
& dlgProgBarWidth & "; height: " & dlgProgBarHeight & ";"
wdBar = 1 * dlgBarWidth
End If

If blnProgressMode Then
Set IE = CreateObject("InternetExplorer.Application")
'strScriptVer = "version would go here"

strTempFile = WshSysEnv("TEMP") & "\progress.htm"
ws.CreateTextFile (strTempFile)
Set f1 = ws.GetFile(strTempFile)
Set ts = f1.OpenAsTextStream(2, True)
ts.WriteLine("<!-- saved from url=(0014)about:internet -->")
ts.WriteLine("<html><head><title>" & dbgTitle & " " & strScriptVer &
" </title>")
ts.WriteLine("<style>.errortext {color:red}")
ts.WriteLine(".hightext {color:blue}</style>")
ts.WriteLine("</head>")
ts.WriteLine(strHDRCode & " <br><strong><font size='2' color='" & fcolor &
"' face='" & fstyle & "'>" _
& "&nbsp Running Windows Update Client...<br>" _
& "&nbsp &nbsp<br>")
ts.WriteLine("<center><table width='100%' bgcolor='" & bgcolor1 &
"'><tr><td>")
If blnDebugMode Then
ts.WriteLine("<body bgcolor ='" & stsBGColor & "' scroll='yes'
topmargin='0' leftmargin='0'"_
& " style='font-family: " & fstyle & "; font-size: 0.6em color: #000000;"_
& " font-weight: bold; text-align: left'><center><font face=" & fstyle &
">"_
& " <font size='0.8em'> <hr color='blue'>")
Else
ts.WriteLine("<body bgcolor = '" & stsBGColor & "' scroll='no'
topmargin='0' leftmargin='0' "_
& " style='font-family: " & fstyle & "; font-size: 0.6em color: #000000;"_
& " font-weight: bold; text-align: left'><center><font face=" & fstyle &
">"_
& " <font size='0.8em'> <hr color='blue'>")
End If
ts.WriteLine("<div id='ProgObject' align='left'align='left' style='width:
450px;height: 140px;overflow:scroll'></div><hr color='blue'>")
If blnDebugMode Then
ts.WriteLine("<div id='ProgDebug' align='left'></div>")
End If

ts.WriteLine("<script LANGUAGE='JavaScript1.2'>")
ts.WriteLine("<!-- Begin")
ts.WriteLine("function initArray() {")
ts.WriteLine("this.length = initArray.arguments.length;")
ts.WriteLine("for (var i = 0; i < this.length; i++) {")
ts.WriteLine("this[i] = initArray.arguments[i];")
ts.WriteLine(" }")
ts.WriteLine("}")
ts.WriteLine("var ctext = ' ';")
ts.WriteLine("var speed = 1000;")
ts.WriteLine("var x = 0;")
ts.WriteLine("var color = new initArray(")
ts.WriteLine("'red',")
ts.WriteLine("'blue'")
ts.WriteLine(");")
ts.WriteLine("document.write('<div id=" & Chr(34) & "ProgFlash" & Chr(34) &
">"_
& "<center>'+ctext+'</center></div>');")
ts.WriteLine("function chcolor(){")
ts.WriteLine("document.all.ProgFlash.style.color = color[x];")
ts.WriteLine("(x < color.length-1) ? x++ : x = 0;")
ts.WriteLine("}")
ts.WriteLine("setInterval('chcolor()',1000);")
ts.WriteLine("// End -->")
ts.WriteLine("</script>")
ts.WriteLine("<div id='ProgBarId' align='left'></div>")
ts.WriteLine("</font></center>")
ts.WriteLine("</tr></td>")
ts.WriteLine("</table></center>")
ts.WriteLine("</body></html>")
ts.Close
fctSetupIE(strTempFile)
Set objDIV = IE.Document.All("ProgObject")
If blnDebugMode Then
Set objDBG = IE.Document.All("ProgDebug")
End If
Set objFlash = IE.Document.All("ProgFlash")
Set objPBar = IE.Document.All("ProgBarId")
Set objBar = IE.Document
End If
If silent = 1 Then
'remarked by Rob Set logwindow = ie.document.all.text1
End If
End Function
'*******************************************************************
'* Name: fctSetupIE
'* Function: Setup an IE windows of 540 x 200 to display
'* progress information.
'*******************************************************************
Sub fctSetupIE(File2Load)
IE.Navigate File2Load
IE.ToolBar = dbgToolBar
IE.StatusBar = dbgStatusBar
IE.Resizable = dbgResizable
Do
Loop While IE.Busy
IE.Width = dbgWidth
IE.Height = dbgHeight
IE.Left = dbgLeft
IE.Top = dbgTop
IE.Visible = dbgVisible
wshshell.AppActivate("Microsoft Internet Explorer")
End Sub


Torgeir Bakken (MVP)

unread,
Jul 9, 2005, 6:33:44 AM7/9/05
to
maximillianx wrote:

> Torgeir -
>
> Do you know how to return the SUS server value via the api? I guess I could
> just as easily pull it from the registry, but figured if I was binding to
> the object already, I might as well take the opportunity to pull as much
> info from it as I can...

I would think reading it from the registry is the best option
(and maybe the only one).

Regards,
Torgeir

Rik

unread,
Jul 11, 2005, 5:23:25 AM7/11/05
to
Hi,

maximillianx wrote:

> You'd want to post in here:
> news:microsoft.public.windows.server.update_services or possibly a
> .Net group... I'd like to see some information on this as well, but
> I'd like to see some VBScript implementation.

I was avoiding that group because it seemed to me that the WUA API
could be used to scan a machine independent of WSUS - something which
interests me.

I found the Microsoft vbscript examples, but their examples all fail
for me, although MBSA 2 manages to identify one patch needed on my test
PC. I figured there was something missing from their example. (Some
connection between IUpdateSession and IUpdateServiceManager possibly).

Cheers,
Rik


Rik

unread,
Jul 11, 2005, 5:26:36 AM7/11/05
to
Hi Torgeir,

Thanks for posting the links. I'd already worked through the ones on
the WUA MSDN pages.

Torgeir Bakken (MVP) wrote:

> Below are what I know of VBScript examples that uses the Windows
> Update Agent API that is documented here:
> http://msdn.microsoft.com/library/en-us/wua_sdk/wua/portal_client.asp

So far, those examples have failed for me. Admittedly, I'm converting
them from VBScript to Delphi, but I'm confident I've not made any
mistakes. They either generate errors, or if I set IUpdateSearcher to
online=false then they return an updatecount of 0, despite MBSA2
returning one required update.


> "View Installation History" for WU5 without using the WU Web site
> http://groups.google.co.uk/group/microsoft.public.windowsupdate/msg/de
> e85221176110ad?dmode=source&hl=en

This one, however, works perfectly. Which is odd, because at no point
in this example is there a call to load wsusscan.cab, which is
confusing.

Cheers,
Rik

Torgeir Bakken (MVP)

unread,
Jul 11, 2005, 6:41:47 AM7/11/05
to
Rik wrote:

> Torgeir Bakken (MVP) wrote:
>
(snip)


>
>> "View Installation History" for WU5 without using the WU Web site
>> http://groups.google.co.uk/group/microsoft.public.windowsupdate/
>> msg/dee85221176110ad?dmode=source&hl=en
>
>
> This one, however, works perfectly. Which is odd, because at no
> point in this example is there a call to load wsusscan.cab, which
> is confusing.

Hi,

The script doesn't use wsusscan.cab.

Note that the script in the link above does not scan for installed or
missing updates, it just uses the QueryHistory method to obtain the
Windows Updates history (that is stored in the database file
%windir%\SoftwareDistribution\DataStore\DataStore.edb

If you stop the Automatic Updates service and then delete that file,
the history information will be gone, and the script in the link above
will not report anything (until Windows Update/Automatic Updates have
done some new installations).

Rik

unread,
Jul 11, 2005, 7:04:45 AM7/11/05
to
Hi Torgeir,

> The script doesn't use wsusscan.cab.

Yep, I realised a couple of minutes ago that I'd made no sense in my
last post. *8)


> Note that the script in the link above does not scan for installed or
> missing updates, it just uses the QueryHistory method to obtain the
> Windows Updates history (that is stored in the database file
> %windir%\SoftwareDistribution\DataStore\DataStore.edb

Which is also really useful, just another area where the documentation
seems a bit light.

Thanks for the clarification. I'm going to go back to trying to get
WUA to give me a list of the patches it can look for from wsusscan.cab.
It can't be as hard to do as it seems to be.

Cheers,
Rik

Reply all
Reply to author
Forward
0 new messages