Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Skip Internet Explorer 11 - Windows Update vbscript

$
0
0

Hello all

I found this great script allowing to skip certain Microsoft Updates. The SkipUpdates Array works great for excluding Bing and Microsoft Essential or even KB numbers, however for Internet Explorer 11, it continues to install despite using different methods from using IE11's KB article number to Internet Explorer keyword (for example: "Internet Explorer" or "Internet Explorer for Windows 7" . Below is the script.

Any ideas?

Const ssDefault = 3
 Const ssManagedServer = 1 
 Const ssOthers = 3 'Microsoft Updates
 Const ssWindowsUpdate = 2 'Windows Updates
 'Array of updates to skip. 
 SkipUpdates = Array("Internet Explorer", "Microsoft Security Essentials", "Bing")
 '#############################
 ' Create Session
 '#############################
 Set UpdateSession = CreateObject("Microsoft.Update.Session")
 Set UpdateSearcher = UpdateSession.CreateUpdateSearcher()
 '#############################
 ' Register Microsoft Update
 '#############################
 RegisterMu
 updateSearcher.ServerSelection = ssOthers '<==== **** CHANGE THIS TO YOUR PREFERENCE ****
 updateSearcher.ServiceID = "7971f918-a847-4430-9279-4a52d1efe18d"
 '#############################
 ' Create List of Updates to Download
 '#############################
 Set UpdatesToDownload = CreateObject("Microsoft.Update.UpdateColl")
 '#############################
 ' Search for Updates
 '#############################
 Set SearchResult = UpdateSearcher.Search("Isinstalled=0")
 '#############################
 ' Quit if No Updates Found
 '#############################
 If SearchResult.Updates.Count = 0 Then
     WScript.Echo "No updates found."
 WScript.Quit
 End If
 Dim strSpacer
 For I = 0 To SearchResult.Updates.Count-1
     Set Update = SearchResult.Updates.Item(I)
 
     ' formatting helper
     If I < 10 Then
         strSpacer = " "
     Else
         strSpacer = ""
     End If
 
     'Check updates to skip
 bSkip = false
 For Each Name in SkipUpdates
 If Instr(LCase(update.Title), LCase(Name)) > 0 Then
 bSkip = True
 Exit For
 End if
 Next
 If bSkip = True Then
 WScript.Echo "Skipping update " & update.Title
 Else
 'WScript.Echo "[" & strSpacer & I & "]  Found Update, Marking For Download:  " & update.Title
 UpdatesToDownload.Add(Update)
 End if 
 
 Next
 '#############################
 ' Download Updates
 '#############################
 Set Downloader = UpdateSession.CreateUpdateDownloader()
 Downloader.Updates = UpdatesToDownload
 On Error Resume Next
 Downloader.Download()
 If Err.number <> 0 Then
     Wscript.Echo "An error occurred in  Downloader.Download() of updates"
     Wscript.Echo "Number: " & err.number
     Wscript.Echo "Description:  " & err.Description
     Wscript.Quit (Err.number)
 End If
 On Error Goto 0
 '#############################
 ' Create List of Updates to Install
 '#############################
 Set UpdatesToInstall = CreateObject("Microsoft.Update.UpdateColl")
 For I = 0 To SearchResult.Updates.Count-1
     set Update = SearchResult.Updates.Item(I)
     If Update.IsDownloaded = true Then
         UpdatesToInstall.Add(Update)
     End If
 Next
 '#############################
 ' Install Updates
 '#############################
 Set Installer = UpdateSession.CreateUpdateInstaller()
 Installer.Updates = UpdatesToInstall
 Set InstallationResult = Installer.Install()
 wscript.Echo "Installation Result: " & InstallationResult.ResultCode
 wscript.Echo "Reboot Required: " & InstallationResult.RebootRequired
 wscript.Echo "Listing of updates installed and individual installation results:"
 
     For I = 0 to UpdatesToInstall.Count - 1
         WScript.Echo I + 1 & "> " & Chr(9) & UpdatesToInstall.Item(I).Title & Chr(9) & ": " & TranslateMuCode(InstallationResult.GetUpdateResult(i).ResultCode)
     Next
 '#############################
 ' Quit
 '#############################
 WScript.Quit
 '================================================================================
 ' Translate Microsoft Update Installation Results
 '================================================================================
 Function TranslateMuCode(theCode)
   TranslateMuCode = "[" & theCode & "] "
   if (theCode = 0) Then TranslateMuCode = TranslateMuCode & "Not Started"
   if (theCode = 1) Then TranslateMuCode = TranslateMuCode & "In Progress"
   if (theCode = 2) Then TranslateMuCode = TranslateMuCode & "Succeeded"
   if (theCode = 3) Then TranslateMuCode = TranslateMuCode & "Succeeded with Errors"
   if (theCode = 4) Then TranslateMuCode = TranslateMuCode & "Failed"
   if (theCode = 5) Then TranslateMuCode = TranslateMuCode & "Aborted"
 End Function
 '================================================================================
 ' Register Microsoft Update (if never registered)
 '================================================================================
 Function RegisterMu
     Dim fso
     Dim file
     Dim WshShell
     Dim updateService
     Dim updateServiceManager
 
     found = false
 
     Set fso = CreateObject("Scripting.FileSystemObject")    
     Set WshShell = WScript.CreateObject ("WScript.Shell")
 
     Set updateServiceManager = CreateObject("Microsoft.Update.ServiceManager")
     Set updateService = updateServiceManager.Services
 
     If err <> 0 Then
         WScript.Echo "CreateObject(Microsoft.Update.ServiceManager) failed with error 0x" & Hex(err.Number)  & err.Description
         WScript.Quit(2)
     End If
     For I=0 to updateService.Count - 1
         Set item = updateService.Item(i)
         If item.ServiceID = "7971f918-a847-4430-9279-4a52d1efe18d" Then
             found = true
         End IF
     Next    
 
     IF found = false Then
         updateServiceManager.AddService2 "7971f918-a847-4430-9279-4a52d1efe18d", 2, ""
 
         If err <> 0 Then
             WScript.Echo "updateServiceManager.AddService() failed with error 0x" & Hex(err.Number) & err.Description
         Else
             WScript.Echo "MU is registered with WU Agent"
         End IF
     End IF
 END Function


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>