title: VB Script to Check, Download, and Install Windows Updates from Microsoft with Exclusions in a text file
body: <p>I have a script that will check, download, and install windows updates.  Got the basic script from <a href="http://gallery.technet.microsoft.com/scriptcenter/VB-Script-to-Check-and-620579cd#content" rel="nofollow">http://gallery.technet.microsoft.com/scriptcenter/VB-Script-to-Check-and-620579cd#content</a>.</p>
  
  <p>I'm trying to exclude specific updates by reading a text file containing the fully qualified name of the update.  If I only have 1 line in my text file, it works great.  When I have multiple line, the script shows multiple results of the update being excluded and also added.  It's probably just the placement of my For Next loops but I'm banging my head.  Here's the section of my script I'm having problems with:</p>
  
  <pre><code>'Create collection of updates to download
  WScript.Echo vbCRLF &amp; "Creating collection of updates to download:"
  Set updatesToDownload = CreateObject("Microsoft.Update.UpdateColl")
  Set objFSO = CreateObject("Scripting.FileSystemObject") 
  Set objFile = objFSO.OpenTextFile("C:\Source\Scripts\CheckUpdates\CheckUpdates\ExcludedUpdates.txt", ForReading) 
  Const ForReading = 1 
  Dim arrExclusions() 
  i = 0 
  Do Until objFile.AtEndOfStream 
  Redim Preserve arrExclusions(i) 
  arrExclusions(i) = objFile.ReadLine 
  i = i + 1 
  Loop 
  objFile.Close
  For I = 0 to searchResult.Updates.Count-1
  Set update = searchResult.Updates.Item(I)
  addThisUpdate = false
  For each strExcludedUpdate in arrExclusions
      If update.Title = strExcludedUpdate Then
          Wscript.Echo I + 1 &amp; "&gt; EXCLUDED: " &amp; update.Title 
          addThisUpdate = false
      Else
          If update.InstallationBehavior.CanRequestUserInput = true Then
          WScript.Echo I + 1 &amp; "&gt; Skipping: " &amp; update.Title &amp; _
          " because it requires user input"
          Else
              If update.EulaAccepted = false Then
                  WScript.Echo vbCrLf &amp; I + 1 &amp; "&gt; NOTE: " &amp; update.Title &amp; _
                  " has a license agreement that must be accepted:"
                  WScript.Echo update.EulaText
                  WScript.Echo vbCrLF &amp; "Do you accept this license agreement? (Y/N)"
                  strInput = WScript.StdIn.ReadLine
                  'strInput = "Y"     'remove remark to auto answer Y (Yes) without user input.
                  WScript.Echo 
                  If (strInput = "Y" or strInput = "y") Then
                      update.AcceptEula()
                      addThisUpdate = true
                  Else
                      WScript.Echo I + 1 &amp; "&gt; ----- Skipping: " &amp; update.Title &amp; _
                      " because the license agreement was declined"
                  End If
              Else
                  addThisUpdate = true
              End If
          End If
      End If
  Next
  If addThisUpdate = true Then
      WScript.Echo I + 1 &amp; "&gt; ADDING: " &amp; update.Title 
      updatesToDownload.Add(update)
  End If
      Next
  
      If updatesToDownload.Count = 0 Then
        WScript.Echo vbCrLf &amp; "No applicable updates to download. Closing in 5 seconds..."
  WScript.Sleep 5000
        WScript.Quit
      End If
  </code></pre>