$ServiceStatus = IsServiceRunning("wuauserv")
If $ServiceStatus[0] = "Running"
? "Automatic Updates is Running"
If InStr($ServiceStatus[1],"Auto")
? "Automatic Updates is set to Auto"
Else
If ChangeServiceState("wuauserv","Automatic")=0
? "Automatic Updates Has Been Set to AUTO"
Else
? "Error Setting Automatic Updates to AUTO"
Endif
EndIf
Else
If ChangeServiceRunState("wuauserv","Start")=0
? "Automatic Updates Has Been Started"
If ChangeServiceState("wuauserv","Automatic")=0
? "Automatic Updates Has Been Set to AUTO"
Else
? "Error Setting Automatic Updates to AUTO"
EndIf
Else
? "Error Starting Automatic Updates, Still not Running"
EndIf
EndIf
get $
Function IsServiceRunning($svc)
; Returns a 2 element array with the Running status[0] and the start mode [1]
$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"+@WkSta+"\root\cimv2")
$colListOfServices = $objWMIService.ExecQuery("Select * from Win32_Service WHERE Name='$svc'")
For Each $objService in $colListOfServices
$IsServiceRunning = $objService.State,$objService.StartMode
Next
EndFunction
Function ChangeServiceState($svc,$state)
;Call function with either 'Automatic','Manual', or 'Disabled'
$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"+@WkSta+"\root\cimv2")
$colListOfServices = $objWMIService.ExecQuery("Select * from Win32_Service WHERE Name='$svc'")
For Each $objService in $colListOfServices
$ChangeServiceState = $objService.ChangeStartMode($state)
Next
EndFunction
Function ChangeServiceRunState($svc,$runstate)
;Call function with either 'Start' or 'Stop'
$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"+@WkSta+"\root\cimv2")
$colListOfServices = $objWMIService.ExecQuery("Select * from Win32_Service WHERE Name='$svc'")
For Each $objService in $colListOfServices
If $runstate="Start"
$ChangeServiceRunState = $objService.StartService()
Else
If $runstate="Stop"
$ChangeServiceRunState = $objService.StopService()
Else
Exit 87
EndIf
EndIf
Next
EndFunction