home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2006 May / PCpro_2006_05.ISO / files / free_security / msshared / Shared_Computer_Toolkit_ENU.msi / FileBin014 < prev    next >
Encoding:
Text (UTF-16)  |  2005-09-02  |  17.5 KB  |  210 lines

  1. ' ***
  2. ' *** ------------------------------------------------------------------------------
  3. ' *** Filename:        WindowsUpdates.vbs
  4. ' *** ------------------------------------------------------------------------------
  5. ' *** Description:    Automatically downloads and installs relevant updates
  6. ' *** ------------------------------------------------------------------------------
  7. ' *** Version:        1.0
  8. ' *** Notes:        
  9. ' *** ------------------------------------------------------------------------------
  10. ' *** Copyright (C) Microsoft Corporation 2005, All Rights Reserved
  11. ' *** ------------------------------------------------------------------------------
  12. ' *** 
  13.  
  14. ' ~~~ 
  15. ' ~~~ Force variables to be declared 
  16. ' ~~~ 
  17. Option Explicit
  18.  
  19. Dim I, I2, oSession, oSearcher, oSearchResult, oUpdate, oUpdatesToDownload, oUpdatesToInstall, oDownloader, oInstaller, oInstallationResult
  20.  
  21. ' ~~~ ------------------------------------------------------------------------------
  22. ' ~~~ Create objects
  23. ' ~~~ ------------------------------------------------------------------------------
  24. Set oSession       = CreateObject("Microsoft.Update.Session")
  25. Set oSearcher      = oSession.CreateupdateSearcher()
  26.  
  27. Public Function DoWindowsUpdates
  28.  
  29. On Error Resume Next
  30.  
  31.     ' ~~~ ------------------------------------------------------------------------------
  32.     ' ~~~ Search for updates
  33.     ' ~~~ ------------------------------------------------------------------------------
  34.     WScript.Echo "Searching for updates..." & vbCRLF
  35.     WScript.Echo "List of applicable items on the machine:"
  36.     
  37.     I2=0
  38.     For I = 0 To oSearchResult.Updates.Count-1
  39.         Set oUpdate = oSearchResult.Updates.Item(I)
  40.         I2=I2+1
  41.         WScript.Echo I + 1 & "> " & oUpdate.Title
  42.     Next
  43.     
  44.     If I2 = 0 Then
  45.         WScript.Echo "There are no applicable updates."
  46.         Exit Function        
  47.     End If
  48.     
  49.     ' ~~~ ------------------------------------------------------------------------------
  50.     ' ~~~ Create collection of upates to download
  51.     ' ~~~ ------------------------------------------------------------------------------
  52.     WScript.Echo vbCRLF & "Creating collection of updates to download:"
  53.     Set oUpdatesToDownload = CreateObject("Microsoft.Update.UpdateColl")
  54.     
  55.     For I = 0 to oSearchResult.Updates.Count-1
  56.         Set oUpdate = oSearchResult.Updates.Item(I)
  57.         WScript.Echo I + 1 & "> adding: " & oUpdate.Title 
  58.         oUpdatesToDownload.Add(oUpdate)
  59.     Next
  60.     
  61.     ' ~~~ ------------------------------------------------------------------------------
  62.     ' ~~~ Download updates
  63.     ' ~~~ ------------------------------------------------------------------------------
  64.     WScript.Echo vbCRLF & "Downloading updates..."
  65.     
  66.     Set oDownloader = oSession.CreateUpdateDownloader() 
  67.     oDownloader.Updates = oUpdatesToDownload
  68.     oDownloader.Download()
  69.     
  70.     ' ~~~ ------------------------------------------------------------------------------
  71.     ' ~~~ Create a collection of downloaded updates to install
  72.     ' ~~~ ------------------------------------------------------------------------------
  73.     WScript.Echo  vbCRLF & "Creating collection of downloaded updates to install:" 
  74.     Set oUpdatesToInstall = CreateObject("Microsoft.Update.UpdateColl")
  75.     
  76.     For I = 0 To oSearchResult.Updates.Count-1
  77.         Set oUpdate = oSearchResult.Updates.Item(I)
  78.         WScript.Echo I + 1 & "> adding:  " & oUpdate.Title 
  79.         oUpdatesToInstall.Add(oUpdate)    
  80.     Next
  81.     
  82.     ' ~~~ ------------------------------------------------------------------------------
  83.     ' ~~~ Install updates
  84.     ' ~~~ ------------------------------------------------------------------------------
  85.     WScript.Echo "Installing updates..."
  86.     Set oInstaller = oSession.CreateUpdateInstaller()
  87.     oInstaller.Updates = oUpdatesToInstall
  88.     Set oInstallationResult = oInstaller.Install()
  89.     
  90.     ' ~~~ ------------------------------------------------------------------------------
  91.     ' ~~~ Output results of install
  92.     ' ~~~ ------------------------------------------------------------------------------
  93.     WScript.Echo "Installation Result: " & oInstallationResult.ResultCode 
  94.     WScript.Echo "Reboot Required: " & oInstallationResult.RebootRequired & vbCRLF 
  95.     WScript.Echo "Listing of updates installed and individual installation results:" 
  96.     
  97.     For I = 0 to oUpdatesToInstall.Count - 1
  98.         WScript.Echo I + 1 & "> " & oUpdatesToInstall.Item(i).Title & ": " & oInstallationResult.GetUpdateResult(i).ResultCode
  99.     Next
  100.     
  101. End Function
  102.  
  103. ' ~~~ Temporary until proper CategoryID is identified.
  104. Public Function DoWindowsUpdates2
  105.  
  106. On Error Resume Next
  107.  
  108.     ' ~~~ ------------------------------------------------------------------------------
  109.     ' ~~~ Search for updates
  110.     ' ~~~ ------------------------------------------------------------------------------
  111.     WScript.Echo "Searching for updates..." & vbCRLF
  112.     WScript.Echo "List of applicable items on the machine:"
  113.         
  114.     I2=0
  115.     For I = 0 To oSearchResult.Updates.Count-1
  116.         Set oUpdate = oSearchResult.Updates.Item(I)
  117.         If Left(oUpdate.Title,30) = "Critical Update for Windows XP" then
  118.             WScript.Echo I + 1 & "> " & oUpdate.Title
  119.             I2=I2+1
  120.         end If    
  121.     Next
  122.     
  123.     If I2 = 0 Then
  124.         WScript.Echo "There are no applicable updates."
  125.         Exit Function        
  126.     End If
  127.     
  128.     ' ~~~ ------------------------------------------------------------------------------
  129.     ' ~~~ Create collection of upates to download
  130.     ' ~~~ ------------------------------------------------------------------------------
  131.     WScript.Echo vbCRLF & "Creating collection of updates to download:"
  132.     Set oUpdatesToDownload = CreateObject("Microsoft.Update.UpdateColl")
  133.     
  134.     For I = 0 to oSearchResult.Updates.Count-1
  135.         Set oUpdate = oSearchResult.Updates.Item(I)
  136.         If Left(oUpdate.Title,30) = "Critical Update for Windows XP" then
  137.             WScript.Echo I + 1 & "> adding: " & oUpdate.Title 
  138.             oUpdatesToDownload.Add(oUpdate)
  139.         End If
  140.     Next
  141.     
  142.     ' ~~~ ------------------------------------------------------------------------------
  143.     ' ~~~ Download updates
  144.     ' ~~~ ------------------------------------------------------------------------------
  145.     WScript.Echo vbCRLF & "Downloading updates..."
  146.     
  147.     Set oDownloader = oSession.CreateUpdateDownloader() 
  148.     oDownloader.Updates = oUpdatesToDownload
  149.     oDownloader.Download()
  150.     
  151.     ' ~~~ ------------------------------------------------------------------------------
  152.     ' ~~~ Create a collection of downloaded updates to install
  153.     ' ~~~ ------------------------------------------------------------------------------
  154.     WScript.Echo  vbCRLF & "Creating collection of downloaded updates to install:" 
  155.     Set oUpdatesToInstall = CreateObject("Microsoft.Update.UpdateColl")
  156.     
  157.     For I = 0 To oSearchResult.Updates.Count-1
  158.         Set oUpdate = oSearchResult.Updates.Item(I)
  159.         If Left(oUpdate.Title,30) = "Critical Update for Windows XP" then
  160.             WScript.Echo I + 1 & "> adding:  " & oUpdate.Title 
  161.             oUpdatesToInstall.Add(oUpdate)    
  162.         End If
  163.     Next
  164.     
  165.     ' ~~~ ------------------------------------------------------------------------------
  166.     ' ~~~ Install updates
  167.     ' ~~~ ------------------------------------------------------------------------------
  168.     WScript.Echo "Installing updates..."
  169.     Set oInstaller = oSession.CreateUpdateInstaller()
  170.     oInstaller.Updates = oUpdatesToInstall
  171.     Set oInstallationResult = oInstaller.Install()
  172.     
  173.     ' ~~~ ------------------------------------------------------------------------------
  174.     ' ~~~ Output results of install
  175.     ' ~~~ ------------------------------------------------------------------------------
  176.     WScript.Echo "Installation Result: " & oInstallationResult.ResultCode 
  177.     WScript.Echo "Reboot Required: " & oInstallationResult.RebootRequired & vbCRLF 
  178.     WScript.Echo "Listing of updates installed and individual installation results:" 
  179.     
  180.     For I = 0 to oUpdatesToInstall.Count - 1
  181.         If Left(oUpdate.Title,30) = "Critical Update for Windows XP" then
  182.             WScript.Echo I + 1 & "> " & oUpdatesToInstall.Item(i).Title & ": " & oInstallationResult.GetUpdateResult(i).ResultCode
  183.         End If    
  184.     Next
  185.     
  186. End Function
  187.  
  188. On Error Resume Next
  189.  
  190. Wscript.Echo "Downloading and Installing Update Rollups"
  191. Set oSearchResult  = oSearcher.Search("IsInstalled=0 and Type='Software' and CategoryIDs contains '28BC880E-0592-4CBF-8F95-C79B17911D5F'")
  192. Call DoWindowsUpdates
  193. wscript.echo vbCRLF
  194.  
  195. Wscript.Echo "Downloading and Installing Security Updates"
  196. Set oSearchResult  = oSearcher.Search("IsInstalled=0 and Type='Software' and CategoryIDs contains '0FA1201D-4330-4FA8-8AE9-B877473B6441'")
  197. Call DoWindowsUpdates
  198. wscript.echo vbCRLF
  199.  
  200. wscript.echo "Downloading and Installing Service Packs"
  201. Set oSearchResult  = oSearcher.Search("IsInstalled=0 and Type='Software' and CategoryIDs contains '68C5B0A3-D1A6-4553-AE49-01D3A7827828'")
  202. Call DoWindowsUpdates
  203. wscript.echo vbCRLF
  204.  
  205. ' ~~~ Temporary until proper Category is identified.
  206. wscript.echo "Downloading and Installing Critical Updates"
  207. Set oSearchResult  = oSearcher.Search("IsInstalled=0 and Type='Software'")
  208. Call DoWindowsUpdates2
  209. wscript.echo vbCRLF
  210.