Deployment Solution

 View Only

Altiris Deployment Server - Install Automatic Updates 

Apr 21, 2009 05:02 PM

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)

Statistics
0 Favorited
0 Views
1 Files
0 Shares
0 Downloads
Attachment(s)
zip file
automatic_updates.txt.zip   13 KB   1 version
Uploaded - Feb 25, 2020

Tags and Keywords

Comments

May 04, 2009 03:44 PM

Thanks for the help MyITGuy!

Turned out that the script relies on Automatic Updates to be enabled.  I just set it to 'Notify' rather than install and this was sufficient for the script to be able to run. 

May 04, 2009 09:28 AM

Thanks for the help!

I ran the VBScript on both my DS & the client server that I am trying to install updates on:

DS Results:
This is a Win 2003 R2 SP2 Server
7.0.6000.381 (winmain(wmbla).070730-1740)

Client Server Results:
This is a Win 2003 R2 SP2 Server
7.2.6001.788 ((winmain(wmbla).081016-1330)

Thanks!

Apr 29, 2009 09:20 AM

There is only one known issue with this script that I'm aware of; The script does not work in Deployment Solution 6.9 SP2 (which I currently have a case open).

This might be caused by a version issue. Can you place this code in a file called GetWUAVersion.vbs, run GetWUAVersion.vbs and let me know the version? If it's a version issue, I can update the code to account for it.
MsgBox GetObject("winmgmts:CIM_DataFile.Name='" & CreateObject("WScript.Shell").ExpandEnvironmentStrings("%windir%\system32\wuaueng.dll") & "'").Version

Apr 28, 2009 11:45 AM

 This script will be quite helpful if I can get it to work.  

I setup a task that copies the WLogEvent.exe then runs the script.

According to the Status Detail it errors out just after 'Checking for updates. Return Code = 0' then the error.

I am getting 'Error -2145083392 during script execution' which I found via search that this error is referring to 'AU was unable to service incoming AU calls'.  

Has anyone else successfully ran this script in their environment?

Any thoughts?


Apr 24, 2009 05:15 PM

Duplicate post removed.

Apr 22, 2009 12:34 PM

I remember now, Deployment Solution lets you do the job now, fast and effective where NS/PM works as you say on the policies and schedules configured within them. Well done, nice script. 

Apr 22, 2009 11:09 AM

Actually, this script picks up where Symantec-Altiris Patch Management falls short; At provisioning. If you want a newly-built system patched quickly, Patch Management is not the answer. Notification Server/Patch Management is good for poll-based management; whereas Deployment Solution is good for active management. Basically active versus passive.

Apr 21, 2009 05:23 PM

This is a nice script to have if you do not have the luxury of Altiris Patch Management Solution in your organization. 

Related Entries and Links

No Related Resource entered.