home *** CD-ROM | disk | FTP | other *** search
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Filename: WindowsUpdates.vbs
- ' *** ------------------------------------------------------------------------------
- ' *** Description: Automatically downloads and installs relevant updates
- ' *** ------------------------------------------------------------------------------
- ' *** Version: 1.0
- ' *** Notes:
- ' *** ------------------------------------------------------------------------------
- ' *** Copyright (C) Microsoft Corporation 2005, All Rights Reserved
- ' *** ------------------------------------------------------------------------------
- ' ***
-
- ' ~~~
- ' ~~~ Force variables to be declared
- ' ~~~
- Option Explicit
-
- Dim I, I2, oSession, oSearcher, oSearchResult, oUpdate, oUpdatesToDownload, oUpdatesToInstall, oDownloader, oInstaller, oInstallationResult
-
- ' ~~~ ------------------------------------------------------------------------------
- ' ~~~ Create objects
- ' ~~~ ------------------------------------------------------------------------------
- Set oSession = CreateObject("Microsoft.Update.Session")
- Set oSearcher = oSession.CreateupdateSearcher()
-
- Public Function DoWindowsUpdates
-
- On Error Resume Next
-
- ' ~~~ ------------------------------------------------------------------------------
- ' ~~~ Search for updates
- ' ~~~ ------------------------------------------------------------------------------
- WScript.Echo "Searching for updates..." & vbCRLF
- WScript.Echo "List of applicable items on the machine:"
-
- I2=0
- For I = 0 To oSearchResult.Updates.Count-1
- Set oUpdate = oSearchResult.Updates.Item(I)
- I2=I2+1
- WScript.Echo I + 1 & "> " & oUpdate.Title
- Next
-
- If I2 = 0 Then
- WScript.Echo "There are no applicable updates."
- Exit Function
- End If
-
- ' ~~~ ------------------------------------------------------------------------------
- ' ~~~ Create collection of upates to download
- ' ~~~ ------------------------------------------------------------------------------
- WScript.Echo vbCRLF & "Creating collection of updates to download:"
- Set oUpdatesToDownload = CreateObject("Microsoft.Update.UpdateColl")
-
- For I = 0 to oSearchResult.Updates.Count-1
- Set oUpdate = oSearchResult.Updates.Item(I)
- WScript.Echo I + 1 & "> adding: " & oUpdate.Title
- oUpdatesToDownload.Add(oUpdate)
- Next
-
- ' ~~~ ------------------------------------------------------------------------------
- ' ~~~ Download updates
- ' ~~~ ------------------------------------------------------------------------------
- WScript.Echo vbCRLF & "Downloading updates..."
-
- Set oDownloader = oSession.CreateUpdateDownloader()
- oDownloader.Updates = oUpdatesToDownload
- oDownloader.Download()
-
- ' ~~~ ------------------------------------------------------------------------------
- ' ~~~ Create a collection of downloaded updates to install
- ' ~~~ ------------------------------------------------------------------------------
- WScript.Echo vbCRLF & "Creating collection of downloaded updates to install:"
- Set oUpdatesToInstall = CreateObject("Microsoft.Update.UpdateColl")
-
- For I = 0 To oSearchResult.Updates.Count-1
- Set oUpdate = oSearchResult.Updates.Item(I)
- WScript.Echo I + 1 & "> adding: " & oUpdate.Title
- oUpdatesToInstall.Add(oUpdate)
- Next
-
- ' ~~~ ------------------------------------------------------------------------------
- ' ~~~ Install updates
- ' ~~~ ------------------------------------------------------------------------------
- WScript.Echo "Installing updates..."
- Set oInstaller = oSession.CreateUpdateInstaller()
- oInstaller.Updates = oUpdatesToInstall
- Set oInstallationResult = oInstaller.Install()
-
- ' ~~~ ------------------------------------------------------------------------------
- ' ~~~ Output results of install
- ' ~~~ ------------------------------------------------------------------------------
- WScript.Echo "Installation Result: " & oInstallationResult.ResultCode
- WScript.Echo "Reboot Required: " & oInstallationResult.RebootRequired & vbCRLF
- WScript.Echo "Listing of updates installed and individual installation results:"
-
- For I = 0 to oUpdatesToInstall.Count - 1
- WScript.Echo I + 1 & "> " & oUpdatesToInstall.Item(i).Title & ": " & oInstallationResult.GetUpdateResult(i).ResultCode
- Next
-
- End Function
-
- ' ~~~ Temporary until proper CategoryID is identified.
- Public Function DoWindowsUpdates2
-
- On Error Resume Next
-
- ' ~~~ ------------------------------------------------------------------------------
- ' ~~~ Search for updates
- ' ~~~ ------------------------------------------------------------------------------
- WScript.Echo "Searching for updates..." & vbCRLF
- WScript.Echo "List of applicable items on the machine:"
-
- I2=0
- For I = 0 To oSearchResult.Updates.Count-1
- Set oUpdate = oSearchResult.Updates.Item(I)
- If Left(oUpdate.Title,30) = "Critical Update for Windows XP" then
- WScript.Echo I + 1 & "> " & oUpdate.Title
- I2=I2+1
- end If
- Next
-
- If I2 = 0 Then
- WScript.Echo "There are no applicable updates."
- Exit Function
- End If
-
- ' ~~~ ------------------------------------------------------------------------------
- ' ~~~ Create collection of upates to download
- ' ~~~ ------------------------------------------------------------------------------
- WScript.Echo vbCRLF & "Creating collection of updates to download:"
- Set oUpdatesToDownload = CreateObject("Microsoft.Update.UpdateColl")
-
- For I = 0 to oSearchResult.Updates.Count-1
- Set oUpdate = oSearchResult.Updates.Item(I)
- If Left(oUpdate.Title,30) = "Critical Update for Windows XP" then
- WScript.Echo I + 1 & "> adding: " & oUpdate.Title
- oUpdatesToDownload.Add(oUpdate)
- End If
- Next
-
- ' ~~~ ------------------------------------------------------------------------------
- ' ~~~ Download updates
- ' ~~~ ------------------------------------------------------------------------------
- WScript.Echo vbCRLF & "Downloading updates..."
-
- Set oDownloader = oSession.CreateUpdateDownloader()
- oDownloader.Updates = oUpdatesToDownload
- oDownloader.Download()
-
- ' ~~~ ------------------------------------------------------------------------------
- ' ~~~ Create a collection of downloaded updates to install
- ' ~~~ ------------------------------------------------------------------------------
- WScript.Echo vbCRLF & "Creating collection of downloaded updates to install:"
- Set oUpdatesToInstall = CreateObject("Microsoft.Update.UpdateColl")
-
- For I = 0 To oSearchResult.Updates.Count-1
- Set oUpdate = oSearchResult.Updates.Item(I)
- If Left(oUpdate.Title,30) = "Critical Update for Windows XP" then
- WScript.Echo I + 1 & "> adding: " & oUpdate.Title
- oUpdatesToInstall.Add(oUpdate)
- End If
- Next
-
- ' ~~~ ------------------------------------------------------------------------------
- ' ~~~ Install updates
- ' ~~~ ------------------------------------------------------------------------------
- WScript.Echo "Installing updates..."
- Set oInstaller = oSession.CreateUpdateInstaller()
- oInstaller.Updates = oUpdatesToInstall
- Set oInstallationResult = oInstaller.Install()
-
- ' ~~~ ------------------------------------------------------------------------------
- ' ~~~ Output results of install
- ' ~~~ ------------------------------------------------------------------------------
- WScript.Echo "Installation Result: " & oInstallationResult.ResultCode
- WScript.Echo "Reboot Required: " & oInstallationResult.RebootRequired & vbCRLF
- WScript.Echo "Listing of updates installed and individual installation results:"
-
- For I = 0 to oUpdatesToInstall.Count - 1
- If Left(oUpdate.Title,30) = "Critical Update for Windows XP" then
- WScript.Echo I + 1 & "> " & oUpdatesToInstall.Item(i).Title & ": " & oInstallationResult.GetUpdateResult(i).ResultCode
- End If
- Next
-
- End Function
-
- On Error Resume Next
-
- Wscript.Echo "Downloading and Installing Update Rollups"
- Set oSearchResult = oSearcher.Search("IsInstalled=0 and Type='Software' and CategoryIDs contains '28BC880E-0592-4CBF-8F95-C79B17911D5F'")
- Call DoWindowsUpdates
- wscript.echo vbCRLF
-
- Wscript.Echo "Downloading and Installing Security Updates"
- Set oSearchResult = oSearcher.Search("IsInstalled=0 and Type='Software' and CategoryIDs contains '0FA1201D-4330-4FA8-8AE9-B877473B6441'")
- Call DoWindowsUpdates
- wscript.echo vbCRLF
-
- wscript.echo "Downloading and Installing Service Packs"
- Set oSearchResult = oSearcher.Search("IsInstalled=0 and Type='Software' and CategoryIDs contains '68C5B0A3-D1A6-4553-AE49-01D3A7827828'")
- Call DoWindowsUpdates
- wscript.echo vbCRLF
-
- ' ~~~ Temporary until proper Category is identified.
- wscript.echo "Downloading and Installing Critical Updates"
- Set oSearchResult = oSearcher.Search("IsInstalled=0 and Type='Software'")
- Call DoWindowsUpdates2
- wscript.echo vbCRLF
-