Using WUA to Scan for Updates Offline

Windows Update Agent (WUA) can be used to scan computers for security updates without connecting to Windows Update or to a Windows Server Update Services (WSUS) server, which enables computers that are not connected to the Internet to be scanned for security updates.

Offline scanning for updates requires the download of a signed file, WsusScan.cab, from Windows Update. Offline scanning for security updates that use Windows Installer require that Windows Installer 3.1 be installed on the computer.

The WsusScan.cab file is a cabinet file that is signed by Microsoft. This file contains security updates. Computers that are not connected to the Internet can be scanned and then updated for the updates in the WsusScan.cab file.

The WsusScan.cab file contains the security updates, update rollups, and service packs that are available from Microsoft Update. The WsusScan.cab file is automatically updated when a security update, update rollup, or service pack is added, removed, or revised on the Microsoft Updates site. The latest WsusScan.cab is available for download at the following location: Download WsusScan.cab

After you download the latest WsusScan.cab, the file can be provided to the AddScanPackageService method, and the WUA API can be used to search the offline computer for security updates. WUA validates that the WsusScan.cab is signed by a valid Microsoft certificate before running an offline scan.

Windows Installer version 3.1 must be installed to search for security updates that use Windows Installer technology. If Windows Installer version 3.1 is not installed, WUA may not return the entire set of updates that are applicable to an offline computer system.

Example

The following example uses the WsusScan.cab file to scan a computer and displays updates that are missing.


Set UpdateSession = CreateObject("Microsoft.Update.Session")
Set UpdateServiceManager = CreateObject("Microsoft.Update.ServiceManager")
Set UpdateService = UpdateServiceManager.AddScanPackageService("Offline Sync Service", "c:\wsusscan.cab")
Set UpdateSearcher = UpdateSession.CreateUpdateSearcher()

WScript.Echo "Searching for updates..." & vbCRLF

UpdateSearcher.ServerSelection = 3 ' ssOthers

UpdateSearcher.ServiceID = UpdateService.ServiceID

Set SearchResult = UpdateSearcher.Search("IsInstalled=0")

Set Updates = SearchResult.Updates

If searchResult.Updates.Count = 0 Then
    WScript.Echo "There are no applicable updates."
    WScript.Quit
End If

WScript.Echo "List of applicable items on the machine when using wssuscan.cab:" & vbCRLF

For I = 0 to searchResult.Updates.Count-1
    Set update = searchResult.Updates.Item(I)
    WScript.Echo I + 1 & "> " & update.Title
Next

WScript.Quit

Send comments about this topic to Microsoft

Build date: 11/18/2009

Tags :


Community Content

JeffreyK16
Needs update for new cab file format
The cab file has been updated.  New version is named 'wsusscn2.cab'.  The code sample should be updated to the new file format, as support for 'wsusscan.cab' will be going away soon.
Tags :

samjcole
This code needs updated

For all people thinking about using this code please see http://support.microsoft.com/?id=927745 for an update, 

 

Sam 

 

Tags :

taurean_h
New Code anyone?

Does anyone have a sample of this code that works in VC?

Can someone please forward me the VC equivalent code for the above sample vb code????????????

Tags : code vc++

Josef Filip
This code is 100% OK

Microsoft has changed the format of the cab file and your older versions of WUA don't know what to do with this new format. You have to upgrade your WUA 2.0 to latest version - read article at http://support.microsoft.com/kb/926464 or you can upgrade your WUA to version 3.0 - read article at http://msdn2.microsoft.com/en-us/library/aa387285.aspx. Upgraded WUA 2.0 works fine for me.

P.S.: This code is 99% OK, you must replace "c:\wsusscan.cab" with "c:\wsusscn2.cab" :-)

P.P.S.: ... or rename wsusscn2.cab to wsusscan.cab :-) :-)

Tags :

Yarborg
How do you do an install from the Cab file?
This code definately shows how to scan a system offline, but how do you do the install of updates referencing the Cab file instead of downloading them from a WSUS server or Microsoft?

I really need to know if anyone has the answer! Thanks!
Tags :

Page view tracker