-
Notifications
You must be signed in to change notification settings - Fork 0
/
DownloadUpdates.vbs
53 lines (43 loc) · 1.82 KB
/
DownloadUpdates.vbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
WScript.Echo "Ensuring .NET 3.5 is installed to ensure COM support in VBScript!"
Set objShell = wscript.CreateObject("wscript.shell")
objShell.Run "%SYSTEMROOT%\System32\dism.exe /Online /NoRestart /Enable-Feature /FeatureName:NetFx3", 0, true
' ========Search Section========
Set updateSession = CreateObject("Microsoft.Update.Session")
updateSession.ClientApplicationID = "Windows Update"
Set updateSearcher = updateSession.CreateUpdateSearcher()
WScript.Echo "Searching for updates..." & vbCRLF
Set searchResult = updateSearcher.Search("IsInstalled=0 and Type='Software' and IsHidden=0")
If searchResult.Updates.Count = 0 Then
WScript.Echo "There are no applicable updates."
WScript.Quit
End If
WScript.Echo "List of applicable items on the machine:"
currentCount = 0
For Each update in searchResult.Updates
currentCount = currentCount + 1
WScript.Echo currentCount & "> " & update.Title
Next
' ========END Search Section========
' ========Download Section========
Set updatesToDownload = CreateObject("Microsoft.Update.UpdateColl")
For Each update in searchResult.Updates
update.AcceptEula()
IF update.isDownloaded = false THEN
updatesToDownload.Add(update)
END IF
Next
WScript.Echo vbCRLF & "Downloading updates..."
currentCount = 0
For Each update in updatesToDownload
Set downloader = updateSession.CreateUpdateDownloader()
currentCount = currentCount + 1
size = Round(CStr(update.MaxDownloadSize) * 0.000001, 2)
WScript.Echo "Downloading " & currentCount & " of " & updatesToDownload.Count & ": " & update.Title & " (Size: " & size & " MBs)"
Set toDownload = CreateObject("Microsoft.Update.UpdateColl")
toDownload.Add(update)
downloader.Updates = toDownload
downloader.Download()
Next
' ========END Download Section========
'We're done here.
WScript.Quit