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()
答案 0 :(得分:2)
必须使用 Microsoft.Update.UpdateColl 来收集要下载的更新。 功能 CopyFromCache 允许下载更新的本地副本。 属性 DownloadURL 将允许您从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