''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' ' File: MSUp.vbs ' Created: 03/12/11 ' Version: 1.0 ' Author(s): Zac H ' ' Purpose: This script is designed to download and install all Microsoft ' updates. ' ' Notes: Originally found here: ' http://msdn.microsoft.com/en-us/library/aa387102(VS.85).aspx ' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Set updateSession = CreateObject(Microsoft.Update.Session) Set updateSearcher = updateSession.CreateupdateSearcher() 'WScript.Echo Searching for updates... & vbCRLF Set searchResult = _ updateSearcher.Search(IsInstalled=0 and Type='Software' and AutoSelectOnWebSites=1) 'WScript.Echo List of applicable items on the machine For I = 0 To searchResult.Updates.Count-1 Set update = searchResult.Updates.Item(I) 'WScript.Echo I + 1 & & update.Title Next If searchResult.Updates.Count = 0 Then 'WScript.Echo There are no applicable updates. 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) If InStr(update.Title, Internet Explorer 9) = 0 And InStr(update.Title, Service Pack) = 0 Then 'WScript.Echo I + 1 & adding & update.Title bDownloads = True updatesToDownload.Add(update) If update.EulaAccepted = False Then update.AcceptEula 'WScript.Echo I + 1 & Accept EULA & update.Title End If End If Next If bDownloads Then 'WScript.Echo vbCRLF & Downloading updates... Set downloader = updateSession.CreateUpdateDownloader() downloader.Updates = updatesToDownload downloader.Download() Else 'WScript.Echo vbCRLF & Nothing to download Wscript.Quit End If 'WScript.Echo vbCRLF & List of downloaded updates For I = 0 To searchResult.Updates.Count-1 Set update = searchResult.Updates.Item(I) If update.IsDownloaded Then If InStr(update.Title, Internet Explorer 9) = 0 And InStr(update.Title, Service Pack) = 0 Then 'WScript.Echo I + 1 & & update.Title End If End If Next Set updatesToInstall = CreateObject(Microsoft.Update.UpdateColl) 'WScript.Echo vbCRLF & Creating collection of downloaded updates to install For I = 0 To searchResult.Updates.Count-1 set update = searchResult.Updates.Item(I) If update.IsDownloaded = true Then If InStr(update.Title, Internet Explorer 9) = 0 And InStr(update.Title, Service Pack) = 0 Then 'WScript.Echo I + 1 & adding & update.Title updatesToInstall.Add(update) End If End If Next 'WScript.Echo Installing updates... Set installer = updateSession.CreateUpdateInstaller() installer.Updates = updatesToInstall Set installationResult = installer.Install() 'Output results of install 'WScript.Echo Installation Result & installationResult.ResultCode 'WScript.Echo Reboot Required & installationResult.RebootRequired & vbCRLF 'WScript.Echo Listing of updates installed and individual installation results For I = 0 to updatesToInstall.Count - 1 'WScript.Echo I + 1 & & updatesToInstall.Item(i).Title & & installationResult.GetUpdateResult(i).ResultCode Next