2

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.

The code follows:

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()
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
MGoBlue93
  • 644
  • 2
  • 14
  • 31
  • The [original script](https://msdn.microsoft.com/library/windows/desktop/aa387102.aspx) is checking for updates that may request user input or present an EULA. Could that be the case here? What does `%windir%\WindowsUpdate.log` say? – Ansgar Wiechers Aug 02 '17 at 09:36
  • @AnsgarWiechers... thanks for the reply. In Win 10, the logs are *.etl files which need to be opened with event viewer. Nevertheless, the logs don't have any warnings or errors. Also, since the original script had the EULA/confirmation stuff after the download, I was hoping it would at least download the KBs first. But it's only downloading one of them -- not all four it says I need. – MGoBlue93 Aug 02 '17 at 14:17
  • Eventually I want to take the KBs and sneaker net them to computers which will NEVER connect to the internet... which is why I'm not interested in the install part of the original script right now. When running the KBs outside of WSUS, the /q switch takes care of the EULA anyway. – MGoBlue93 Aug 02 '17 at 14:17
  • There is a PowerShell code with similar funcionality at [https://gist.github.com/altrive/5268181](https://gist.github.com/altrive/5268181) – JoSerra Aug 03 '17 at 12:01

1 Answers1

3

It must be used Microsoft.Update.UpdateColl to collect updates to download. Function CopyFromCache allows to download a local copy of update. Propertie DownloadURL will allow you to get download from Internet. It was very useful iupdate object documentation

This is my "first" approach to code. First 5 updates are downloaded to d:\updates directory and their corresponding URL are listed.

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 updatesToDownload = CreateObject("Microsoft.Update.UpdateColl")
Set downloader = session.CreateUpdateDownloader() 
'For I = 0 to result.Updates.Count-1
For I = 0 to 5
    Set update = result.Updates.Item(I)
    updatesToDownload.Add(update)
Next
WScript.Echo vbCRLF & "Downloading updates..."
downloader.Updates = updatesToDownload
downloader.Download()

'For I = 0 to result.Updates.Count-1
for i=0 to 5
  for each upd in downloader.Updates.Item(i).BundledUpdates
   upd.CopyFromCache "d:\UPDATES", False
   for each content in upd.DownloadContents
     wscript.echo "url: " & content.DownloadURL
   next 
  next 
next 
JoSerra
  • 361
  • 2
  • 9
  • Thanks @JoSerra... I have to head out of town but I will check this out later. Stay tuned! – MGoBlue93 Aug 04 '17 at 15:34
  • Thanks @JoSerra... Something weird happens though. Your script finds 2 missing updates but only downloads one of them: Searching for updates... Missing KBs: 1> 2017-07 Security Update for Adobe Flash Player for Windows 10 Version 1703 for x64-based Systems (KB4025376) 2> 2017-07 Cumulative Update for Windows 10 Version 1703 for x64-based Systems (KB4032188) – MGoBlue93 Aug 04 '17 at 15:44
  • Downloading updates... url: http://download.windowsupdate.com/d/msdownload/update/software/secu/2017/07/windows10.0-kb4025376-x64_9f431762c6808c64d36c82163b43586cc18c2090.cab c:\Users\dogzilla\Desktop\joserra.vbs(28, 4) (null): 0x80248007 – MGoBlue93 Aug 04 '17 at 15:44
  • To run these scripts you must use elevation privilege (Run as an Administrator option) or 0x80248007 is fired. Missing updates , perhaps, are involved with selection criteria "IsInstalled=0 AND Type='Software' AND IsHidden=0" ? Try another selection. – JoSerra Aug 05 '17 at 06:50
  • That's not it -- I did run as administrator. Have you been able to come across which parameters (e.g., IsInstalled, IsInstalled, IsHidden, etc.) are available? I looked at the CreateUpdateDownloader API on TechNet and it did not have a parameter/argument list. Thanks! – MGoBlue93 Aug 11 '17 at 16:06
  • @MGoBlue93 check [Search syntax](https://msdn.microsoft.com/en-us/library/aa386526(v=vs.85).aspx) – JoSerra Aug 14 '17 at 10:13