VB script to get Automatic Update Service status and start the service if stopped
One of the pre-requirement to deploy ITMU is that the automatic update service should be set to automatic and should be in started state.
Here is a VB script to check the automatic update service status and change it to automatic and start the service if applicable.
Option Explicit
On Error Resume Next
Dim objDictionary
Dim objFSO
Dim objTextFile
Dim strNextLine
Dim strComputer
Dim result
Dim objItem
Dim TxtFile
Dim i
Dim Dping
Dim Pinged
Dim pingresult
Dim arrPingResult
Dim u
Dim objWMIService
Dim colStoppedServices
Dim objService
Const ForReading = 1
TxtFile = "C:\Myworkplace\Clientlist.txt" 'fetch clients list from a txt file to a dictionary
Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
(TxtFile, ForReading)
i = 0
Do Until objTextFile.AtEndofStream
strNextLine = objTextFile.Readline
objDictionary.Add i, strNextLine
i = i + 1
Loop
For Each objItem in objDictionary
strComputer = objDictionary.Item(objItem)
Set Dping = Wscript.Createobject("Dynu.Ping")
Pinged = False
pingresult = DPing.ping(strComputer, 1, 1, 2000) 'ping clients
arrPingResult = Split(PingResult,vbCRLF)
For u = 0 To UBound(arrPingResult)
If InStr(1,arrPingResult(u),"bytes=1",1) > 0 Then
Pinged = True
Set objWMIService = GetObject("winmgmts:" & _
"{impersonationLevel=Impersonate}!\\" & strComputer & "\root\cimv2")
Set colStoppedServices = objWMIService.ExecQuery _
("Select * From Win32_Service Where name = 'Wuauserv'and startMode = 'Disabled'")
For Each objService in colStoppedServices
Wscript.Echo strComputer
Wscript.Echo objService.DisplayName & " = " & objService.StartMode
Wscript.Echo objService.DisplayName & " = " & objService.State
errReturnCode = objService.Change( , , , , "Automatic")
objService.StartService()
Next
End If
Next
If Pinged = False Then
WScript.Echo("Unable to ping " & strComputer)
End if
Next