none
CreateUpdateDownloader not downloading all files. RRS feed

  • General discussion

  • Hello everyone!
    I have a question about scripting the WUA client -- how does CreateUpdateDownloader download files?  I ask because my system is missing 4 KBs. 
    I get the title of the 4 missing KBs from iterating through an update collection in my script.
    When I assign that collection to a CreateUpdateDownloader though, I only find 1 KB in C:\Windows\SoftwareDistribution\Download
    Any thoughts why it didn't download the other 3 KBs?  Yes, I'm only looking to scan and download for right now -- trying to learn how this works by watching it in action.  I'll get to install later as I want to tweak some of that.

    Suggestions are greatly appreciated!  Thanks!  The code follows:

    ' H/T: ' https://msdn.microsoft.com/en-us/library/windows/desktop/aa387102(v=vs.85).aspx

        Dim session : Set session = CreateObject("Microsoft.Update.Session")
        Dim search  : Set search  = session.CreateUpdateSearcher()

        WScript.Echo "Searching for updates..." & vbCRLF

        Set result = search.Search("IsInstalled=0 AND Type='Software' AND IsHidden=0")

        WScript.Echo "Missing KBs:"

        For i = 0 To result.Updates.Count -1 'last item in the collection always seems to be some kind of gibberish null.
            Set update = result.Updates.Item(i)
            WScript.Echo i + 1 & "> " & update.Title
        Next

        If result.Updates.Count = 0 Then
            WScript.Echo "There are no applicable updates."
        End If

        Set downloader = session.CreateUpdateDownloader()
        downloader.Updates = result.Updates ' updatesToDownload
        downloader.Download()

                           
    Tuesday, August 1, 2017 9:58 PM

All replies

  • Use this code:

    Set updateSession = CreateObject("Microsoft.Update.Session")
    updateSession.ClientApplicationID = "MSDN Sample Script"
    
    Set updateSearcher = updateSession.CreateUpdateSearcher()
    
    WScript.Echo "Searching for updates..." & vbCRLF
    
    Set searchResult = _
    updateSearcher.Search("IsInstalled=0 and Type='Software' and IsHidden=0")
    
    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)
        addThisUpdate = false
        If update.InstallationBehavior.CanRequestUserInput = true Then
            WScript.Echo I + 1 & "> skipping: " & update.Title & _
            " because it requires user input"
        Else
            If update.EulaAccepted = false Then
                WScript.Echo I + 1 & "> note: " & update.Title & _
                " has a license agreement that must be accepted:"
                WScript.Echo update.EulaText
                WScript.Echo "Do you accept this license agreement? (Y/N)"
                strInput = WScript.StdIn.Readline
                WScript.Echo 
                If (strInput = "Y" or strInput = "y") Then
                    update.AcceptEula()
                    addThisUpdate = true
                Else
                    WScript.Echo I + 1 & "> skipping: " & update.Title & _
                    " because the license agreement was declined"
                End If
            Else
                addThisUpdate = true
            End If
        End If
        If addThisUpdate = true Then
            WScript.Echo I + 1 & "> adding: " & update.Title 
            updatesToDownload.Add(update)
        End If
    Next
    
    If updatesToDownload.Count = 0 Then
        WScript.Echo "All applicable updates were skipped."
        WScript.Quit
    End If
        
    WScript.Echo vbCRLF & "Downloading updates..."
    
    Set downloader = updateSession.CreateUpdateDownloader() 
    downloader.Updates = updatesToDownload
    downloader.Download()
    
    Set updatesToInstall = CreateObject("Microsoft.Update.UpdateColl")
    
    rebootMayBeRequired = false
    
    WScript.Echo vbCRLF & "Successfully downloaded updates:"
    
    For I = 0 To searchResult.Updates.Count-1
        set update = searchResult.Updates.Item(I)
        If update.IsDownloaded = true Then
            WScript.Echo I + 1 & "> " & update.Title 
            updatesToInstall.Add(update) 
            If update.InstallationBehavior.RebootBehavior > 0 Then
                rebootMayBeRequired = true
            End If
        End If
    Next
    
    If updatesToInstall.Count = 0 Then
        WScript.Echo "No updates were successfully downloaded."
        WScript.Quit
    End If
    
    If rebootMayBeRequired = true Then
        WScript.Echo vbCRLF & "These updates may require a reboot."
    End If
    
    WScript.Echo  vbCRLF & "Would you like to install updates now? (Y/N)"
    strInput = WScript.StdIn.Readline
    WScript.Echo 
    
    If (strInput = "Y" or strInput = "y") Then
        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
    End If
    You would do better to use PowerShell with the WUA module from the gallery:  https://gallery.technet.microsoft.com/2d191bcd-3308-4edd-9de2-88dff796b0bc

    \_(ツ)_/

    Tuesday, August 1, 2017 10:31 PM
  • You keep on pushing your PowerShell translation of the existing TechNet VBScripts in your replies -- that's not what I asked. 

    I unfortunately have very specific requirements in which to operate -- not of my own choosing, and all the stuff I did to automate patch maintenance in previous years doesn't work with Windows 10 changes and I'm trying, unsuccessfully thus far, to remediate that.

    I'm interested in learning how CreateUpdateDownloader works.  The API for it doesn't document much.  The API doesn't document the CreateUpdateSearcher() either... e.g., where are the list of arguments such as IsInstalled or IsHidden in https://msdn.microsoft.com/en-us/library/windows/desktop/aa386865%28v=vs.85%29.aspx?

    Getting back to my OP... specifically, the scan says I'm missing 4 KBs.  I only see one in C:\Windows\SoftwareDistribution\Download  The logs in C:\Windows\Logs\WindowsUpdate don't have any errors or warnings either.  It would be nice to be able to debug CreateUpdateDownloader so I can learn why 3 KBs aren't being updated.

    Wednesday, August 2, 2017 2:08 PM
  • The question of why different Windows Update search methods return different results is a Windows Update-specific question (i.e., outside the scope of this forum).

    Also, I would suggest using PowerShell also. You have mentioned "very specific requirements" that prevent you from using PowerShell (at least, that is how I interpreted your comment). If you are prevented from using PowerShell, this begs some justification because PowerShell is the preferred management method moving forward (particularly with Windows 10).


    -- Bill Stewart [Bill_Stewart]

    Wednesday, August 2, 2017 4:28 PM
    Moderator
  • I did not mean to imply that I had to use a specific technology.  PowerShell is fine.  I'm not married to any languages -- I just want stuff to work.

    What I was getting frustrated with is getting the same answers to 2 different posts; which didn't address my question and advertised someone's contribution to the scripting catalog  -- which again didn't apply to the original question.

    Specifically, here's my situation:

    1.  I have 11 laptops which will never connect to the Internet.  Ever.  There's no need to discuss this part further.

    2.  I have an additional like laptop -- hardware and disk image, which does connect to the internet and I can get KBs from that laptop.

    3.  In the past, I've had a VB script which:

    -- scans for missing KBs

    -- Downloads the missing KBs

    -- Creates an install script for the downloaded KBs

    ... and when that script finishes, I can burn a DVD with the install script and updates and install on the other 11 laptops.

    4.  That script saves me a lot of time and money... I don't have to manually do anything; the scanning and install scripts do all the heavy lifting for me and makes the administration of standalone hosts very easy.

    Well, Windows 10 breaks all that!!!  I understand the term "break" is about perspective here.  But the fact of the matter is in Windows 7, I had a script which automated everything I mentioned above and that no longer works in Windows 10.  For example, the download portion of the previously mentioned script doesn't work since KBs got moved to the catalog website and the download buttons are javascript now.

    Another problem I'm having in trying to regain lost functionality is when I try to download applicable updates using CreateUpdateDownloader, using this code:

    WScript.Echo vbCRLF & "Would you like to install now? (Y/N)"
    stdInput = WScript.StdIn.Readline
     
    If (strInput = "N" or strInput = "n") Then 
       WScript.Quit
    ElseIf  (stdInput = "Y" OR stdInput = "y") Then
       'Download update
       Set downloader = updateSession.CreateUpdateDownloader() 
       downloader.Updates = updateToInstall
       WScript.Echo vbCRLF & "Downloading..."
       Set downloadResult = downloader.Download()
       WScript.Echo "Download Result: " & downloadResult.ResultCode

    The result is:

    Microsoft (R) Windows Script Host Version 5.812
    Copyright (C) Microsoft Corporation. All rights reserved.
    
    Enter the title of the update: (for example, Update for Windows Rights Management client 1.0)
    
    2017-07 Cumulative Update for Windows 10 Version 1703 for x64-based Systems (KB4032188)
    
    Searching for: 2017-07 Cumulative Update for Windows 10 Version 1703 for x64-based Systems (KB4032188)...
    
    Result: Update applicable, not installed.
    
    Would you like to install now? (Y/N)y
    
    Downloading...Download Result: 4

    Not intuitively knowing what error code 4 is, I went here:

    https://msdn.microsoft.com/en-us/library/windows/desktop/hh968413(v=vs.85).aspx

    Is that the right link?

    I ask because this code makes little sense:

    A callback was marked to be disconnected later because the request to disconnect the operation came while a callback was executing.

    Huh?  There's no network problem on my end.  I'm not disconnecting anything -- rather I'm trying to download something.

    I hope this explanation is clearer.  Thanks for your reply!

    Friday, August 4, 2017 3:30 PM
  • The problem is that we don't have the resources to reproduce your specific environment and produce a use-case test where we can dig into the details and troubleshoot this for you.

    Unfortunately we can't provide the level of support you are asking for from afar in a forum.


    -- Bill Stewart [Bill_Stewart]

    Friday, August 4, 2017 3:41 PM
    Moderator
  • Windows Creators Update, when applied by force to a non-candidate system, will cause many issues similar to the one you are seeing.  You will need to remove the update or call Microsoft support for help.

    Microsoft has posted that this is a known issue when the Creators Update has been installed on a system that it was not offered to through the online update system.

    This is not a scripting issue.


    \_(ツ)_/

    Friday, August 4, 2017 3:42 PM
  • Microsoft quote:

    "It’s important to note that when customers use the Software Download Site to manually install the Creators Update they bypass many of these blocks. Therefore, we continue to recommend (unless you’re an advanced user who is prepared to work through some issues) that you wait until the Windows 10 Creators Update is automatically offered to you. When your device becomes eligible for the Creators Update rollout, you’ll be prompted to make some important choices on your privacy settings before the Creators Update can install."


    \_(ツ)_/

    Friday, August 4, 2017 3:46 PM
  •  that you wait until the Windows 10Creators Update is automatically offered 

    That will never happen given that 11 of my laptops NEVER connect to the internet!

    Friday, August 11, 2017 4:09 PM
  • Unfortunately we can't provide the level of support you are asking for from afar in a forum.

    Asking how CreateUpdateSearcher works and why it's throwing error code 4 on one of the downloads is beyond the scope of the forum?!?

    Friday, August 11, 2017 4:10 PM
  •  that you wait until the Windows 10Creators Update is automatically offered 

    That will never happen given that 11 of my laptops NEVER connect to the internet!

    Then you may have serious issues after applying the update.  I have two system that are very flaky because I decided to force the update.  Little by little MS has fixed some issues and HP has released a few driver and app fixes but all is still not well.  I am hoping the fall update will fix the remainder.

    On all systems that updated automatically when the update was available there are no noticeable issues.  Some HP systems didn't offer the update until the end of July.  Microsoft says to just wait or force an update at your own peril.


    \_(ツ)_/

    Friday, August 11, 2017 4:13 PM
  • Unfortunately we can't provide the level of support you are asking for from afar in a forum.

    Asking how CreateUpdateSearcher works and why it's throwing error code 4 on one of the downloads is beyond the scope of the forum?!?

    The searcher just returns candidate files.  Some files may not be available or may have been superseded. Some files may not apply to your version of the OS.

    Post in platform forum with exact update ID or read all of the catalogue notes for the package to see what the issues might be.

    I recommend doing your testing with PowerShell as this will allow you to work interactively with the searcher and the returned objects.

    These are all issues we all work with when trying to use automation and the WUA classes.  There is no absolute answer to any specific issue.  It must be analyzed and in understood.


    \_(ツ)_/

    Friday, August 11, 2017 4:19 PM
  • Here is a quick way to grab all failed updates for inspection:

    $session = New-Object -ComObject Microsoft.Update.Session $searcher = $session.CreateUpdateSearcher() $result = $searcher.Search('IsInstalled=0 AND Type=''Software'' AND IsHidden=0') $result.Updates | Select-Object Title # attempt to download updates $downloader = $session.CreateUpdateDownloader() $failed=@() Try{ foreach($udate in $result.Updates){    $downloader = $session.CreateUpdateDownloader()
    $downloader.Updates.Add($update) $rc = $downloader.Download() if($rc.resultCode -ne 2){ $failed += $update } } } Catch{ $failed += $update } Write-Host 'The following downloads failed' $failed



    \_(ツ)_/




    • Edited by jrv Friday, August 11, 2017 4:42 PM
    Friday, August 11, 2017 4:37 PM
  • Asking how CreateUpdateSearcher works and why it's throwing error code 4 on one of the downloads is beyond the scope of the forum?!?

    In order to help, someone has to be able to reproduce your problem environment. Reproducing your problem environment to help you troubleshoot your specific problem is outside the scope of this forum.

    However we can tell you what error code 4 means:


    PS C:\> net helpmsg 4
    The system cannot open the file.
    

    (We can only tell you what the error code means; we can't tell you how you can remediate it in your specific environment.)

    For how CreateUpdateSearcher works, we can only point you to the documentation. (We have the same access to the documentation that you have.)


    -- Bill Stewart [Bill_Stewart]

    Friday, August 11, 2017 5:22 PM
    Moderator
  • FYI - The complete ResultCode list is:

    typedef enum  { 
      orcNotStarted           = 0,
      orcInProgress           = 1,
      orcSucceeded            = 2,
      orcSucceededWithErrors  = 3,
      orcFailed               = 4,
      orcAborted              = 5
    } OperationResultCode;
    
    Which, as Bill noted, means the file download failed.

    These codes also apply to the UpdateInstaller results.

    https://msdn.microsoft.com/en-us/library/windows/desktop/aa387095(v=vs.85).aspx


    \_(ツ)_/

    Friday, August 11, 2017 5:37 PM
  • Thanks for the failed download powershell sample.
    Monday, August 14, 2017 3:25 PM
  • Thanks for the failed download powershell sample.

    You are welcome.

    Unfortunately there is no way to script around this.  You must troubleshoot you system to find out why the updates are failing.  Start by reviewing the log files.  If you are still stuck the place a call to MS Support for assistance repairing your system.


    \_(ツ)_/

    Monday, August 14, 2017 3:36 PM