Here ya go. This version sets the computer to look to our internal windows updates server rather than going to the internet... You'll need to change the two https:myserver.domain.net to point to your own wsus server if you have one...
Code:
'----- Create Registry Settings Required for Workgroup Updating -----
On Error Resume next
Dim oShell
Set oShell = CreateObject("WScript.Shell")
'----- Restart wuauserv Service so Settings Take Effect -----
Set oWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colServiceList = oWMIService.ExecQuery ("Select * from Win32_Service Where Name='wuauserv'")
For Each objService in colServiceList
objService.StopService()
Wscript.Sleep 10000
oShell.RegWrite "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\WUServer", "https://myserver.domain.net:443", "REG_SZ"
oShell.RegWrite "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\WUStatusServer", "https://myserver.domain.net:443", "REG_SZ"
oShell.RegWrite "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AcceptTrustedPublisherCerts", 1, "REG_DWORD"
oShell.RegWrite "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\TargetGroupEnabled", 1, "REG_DWORD"
oShell.RegWrite "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\TargetGroup", "Assigned Computers", "REG_SZ"
oShell.RegWrite "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\ElevateNonAdmins", 1, "REG_DWORD"
oShell.RegWrite "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU\UseWUServer", 1, "REG_DWORD"
oShell.RegWrite "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU\AutoInstallMinorUpdates", 1, "REG_DWORD"
oShell.RegWrite "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU\IncludeRecommendedUpdates", 1, "REG_DWORD"
objService.StartService()
Next
Wscript.Sleep 10000
'----- Create Session -----
Set UpdateSession = CreateObject("Microsoft.Update.Session")
Set UpdateSearcher = UpdateSession.CreateUpdateSearcher()
'----- Search for Updates -----
Set SearchResult = UpdateSearcher.Search("IsInstalled=0 and Type='Software'")
For I = 0 To SearchResult.Updates.Count-1
Set Update = SearchResult.Updates.Item(I)
Next
'----- Quit if No Updates Found -----
If SearchResult.Updates.Count = 0 Then
WScript.Quit
End If
'----- Create List of Updates to Download -----
Set UpdatesToDownload = CreateObject("Microsoft.Update.UpdateColl")
For I = 0 to SearchResult.Updates.Count-1
Set Update = SearchResult.Updates.Item(I)
UpdatesToDownload.Add(Update)
Next
'----- Download Updates -----
Set Downloader = UpdateSession.CreateUpdateDownloader()
Downloader.Updates = UpdatesToDownload
Downloader.Download()
'----- Create List of Updates to Install -----
Set UpdatesToInstall = CreateObject("Microsoft.Update.UpdateColl")
For I = 0 To SearchResult.Updates.Count-1
set Update = SearchResult.Updates.Item(I)
If Update.IsDownloaded = true Then
UpdatesToInstall.Add(Update)
End If
Next
'----- Install Updates -----
Set Installer = UpdateSession.CreateUpdateInstaller()
Installer.Updates = UpdatesToInstall
Installer.Install()
'----- Quit -----
WScript.Quit
If you don't have one this will download the updates from the internet.
Code:
On Error Resume next
'----- Create Session -----
Set UpdateSession = CreateObject("Microsoft.Update.Session")
Set UpdateSearcher = UpdateSession.CreateUpdateSearcher()
'----- Search for Updates -----
Set SearchResult = UpdateSearcher.Search("IsInstalled=0 and Type='Software'")
For I = 0 To SearchResult.Updates.Count-1
Set Update = SearchResult.Updates.Item(I)
Next
'----- Quit if No Updates Found -----
If SearchResult.Updates.Count = 0 Then
WScript.Quit
End If
'----- Create List of Updates to Download -----
Set UpdatesToDownload = CreateObject("Microsoft.Update.UpdateColl")
For I = 0 to SearchResult.Updates.Count-1
Set Update = SearchResult.Updates.Item(I)
UpdatesToDownload.Add(Update)
Next
'----- Download Updates -----
Set Downloader = UpdateSession.CreateUpdateDownloader()
Downloader.Updates = UpdatesToDownload
Downloader.Download()
'----- Create List of Updates to Install -----
Set UpdatesToInstall = CreateObject("Microsoft.Update.UpdateColl")
For I = 0 To SearchResult.Updates.Count-1
set Update = SearchResult.Updates.Item(I)
If Update.IsDownloaded = true Then
UpdatesToInstall.Add(Update)
End If
Next
'----- Install Updates -----
Set Installer = UpdateSession.CreateUpdateInstaller()
Installer.Updates = UpdatesToInstall
Installer.Install()
'----- Quit -----
WScript.Quit
Social Networking Bookmarks