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

最佳答案

必须使用 Microsoft.Update.UpdateColl 来收集要下载的更新。
函数 CopyFromCache 允许下载更新的本地副本。
适当的下载URL 将允许您从Internet获得下载。
iupdate object documentation非常有用

这是我的“第一种”编码方法。
前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

10-08 06:20
查看更多