2

如何CreateUpdateDownloader下载文件?我问是因为我的系统缺少 4 KB。

我通过迭代脚本中的更新集合获得了 4 个缺失 KB 的标题。

当我将该集合分配给一个CreateUpdateDownloader时,我只在 C:\Windows\SoftwareDistribution\Download 中找到 1 KB。

任何想法为什么它没有下载其他 3 KB?是的,我现在只是想扫描和下载——试图通过观察它的运行来了解它是如何工作的。我稍后会安装,因为我想调整其中的一些。

代码如下:

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()
4

1 回答 1

3

它必须使用Microsoft.Update.UpdateColl来收集要下载的更新。函数CopyFromCache允许下载更新的本地副本。属性DownloadURL将允许您从 Internet 下载。这是非常有用的 iupdate 对象文档

这是我编写代码的“第一种”方法。前 5 个更新下载到 d:\updates 目录,并列出了它们对应的 URL。

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 
于 2017-08-03T12:13:19.940 回答