This script runs through the Altiris Deployment Solution allowing the check, download and install of automatic updates.
A prerequisite of this task is to copy WLogevent.exe to the local system.
Currently, this script may require multiple runs as it does not forcibly reboot the system and re-run. I will, hopefully, add that later.
' Install Automatic Updates 'vbscript On Error Resume Next Set objWSHShell = CreateObject("WScript.shell") If Err.Number Then WScript.Quit(Err.Number) objWSHShell.Run ".\WLogevent.exe -c:0 -l:1 -ss:""Checking if a reboot is required before installations""", 1, true Set objSystemInfo = CreateObject("Microsoft.Update.SystemInfo") If Err.Number Then WScript.Quit(Err.Number) If objSystemInfo.RebootRequired = True Then WScript.Quit(3010) Set objAutoUpdate = CreateObject("Microsoft.Update.AutoUpdate") If Err.Number Then WScript.Quit(Err.Number) If objAutoUpdate.ServiceEnabled = False Then objAutoUpdate.EnableService objWSHShell.Run ".\WLogevent.exe -c:0 -l:1 -ss:""Checking for updates""", 1, true objAutoUpdate.DetectNow Set objSession = CreateObject("Microsoft.Update.Session") If Err.Number Then WScript.Quit(Err.Number) Set objUpdateSearcher = objSession.CreateUpdateSearcher() If Err.Number Then WScript.Quit(Err.Number) Set colSearchResults = objUpdateSearcher.Search("IsAssigned=1 AND IsInstalled=0 AND Type='Software'") If Err.Number Then WScript.Quit(Err.Number) If colSearchResults.Updates.Count Then objWSHShell.Run ".\WLogevent.exe -c:0 -l:1 -ss:""Updates found: " & colSearchResults.Updates.Count & """", 1, true Set objUpdateColl_Install = CreateObject("Microsoft.Update.UpdateColl") Set objUpdateColl_Download = CreateObject("Microsoft.Update.UpdateColl") For Each objUpdate In colSearchResults.Updates objWSHShell.Run ".\WLogevent.exe -c:0 -l:1 -ss:""Found: " & objUpdate.Title & """", 1, True If objUpdate.EulaAccepted = False Then objUpdate.AcceptEula If objUpdate.IsDownloaded = False Then objUpdateColl_Download.Add(objUpdate) objUpdateColl_Install.Add(objUpdate) Next If objUpdateColl_Download.Count Then objWSHShell.Run ".\WLogevent.exe -c:0 -l:1 -ss:""Downloading updates: " & objUpdateColl_Download.Count & """", 1, true Set objUpdateDownloader = objSession.CreateUpdateDownloader() objUpdateDownloader.Updates = objUpdateColl_Download objUpdateDownloader.Download() End If If objUpdateColl_Install.Count Then objWSHShell.Run ".\WLogevent.exe -c:0 -l:1 -ss:""Installing updates: " & objUpdateColl_Install.Count & """", 1, True blnRebootRequired = False intLastNonSuccessResultCode = 2 Set objUpdateInstaller = objSession.CreateUpdateInstaller() objUpdateInstaller.Updates = objUpdateColl_Install Set InstallationResult = objUpdateInstaller.Install() For i = 0 to objUpdateColl_Install.Count - 1 Dim ResultDescription Select Case InstallationResult.GetUpdateResult(i).ResultCode Case 0 ResultDescription = "Not Started" Case 1 ResultDescription = "In-Progress" Case 2 ResultDescription = "Succeeded" Case 3 ResultDescription = "Succeeded With Errors" Case 4 ResultDescription = "Failed" Case 5 ResultDescription = "Aborted" End Select If InstallationResult.GetUpdateResult(i).ResultCode <> 2 Then intLastNonSuccessResultCode = InstallationResult.GetUpdateResult(i).ResultCode If InstallationResult.GetUpdateResult(i).RebootRequired = True Then blnRebootRequired = True objWSHShell.Run ".\WLogevent.exe -c:" & InstallationResult.GetUpdateResult(i).ResultCode & " -l:1 -ss:""" & objUpdateColl_Install.Item(i).Title & """", 1, True Next End If objWSHShell.Run ".\WLogevent.exe -c:0 -l:1 -ss:""Checking if a reboot is required after installations (" & blnRebootRequired & ")""", 1, true If blnRebootRequired = True Then WScript.Quit(3010) Else objWSHShell.Run ".\WLogevent.exe -c:0 -l:1 -ss:""No updates to install""", 1, True intLastNonSuccessResultCode = 999992 End If Set objWSHShell = Nothing WScript.Quit(intLastNonSuccessResultCode)
MsgBox GetObject("winmgmts:CIM_DataFile.Name='" & CreateObject("WScript.Shell").ExpandEnvironmentStrings("%windir%\system32\wuaueng.dll") & "'").Version