'On Error Resume Next

strService = "TermService"

'********************************
'read value of regkey
'********************************
Set objShell = CreateObject("WScript.Shell")
strRegKey =  objShell.RegRead("HKLM\System\CurrentControlSet\Services\DHCP\Start")

'********************************
'Read startup type of a service
'********************************
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colListOfServices = objWMIService.ExecQuery _
        ("Select * from Win32_Service WHERE name = '" & strService & "'")
For Each objService in colListOfServices
      strStartupMode = Lcase(objService.StartMode)
Next

'********************************
'Check values and generate an alert
'********************************

If not strStartupMode = "auto" AND strRegKey = "2" Then

'********************************
'Below is what will happend if the regkey value are not 2 and the startup type is not Automatic
'********************************

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _
    ("Select * from Win32_Service where name = 'TermService'")
For Each objService in colServiceList
    errReturnCode = objService.Change( , , , , "Automatic")   
Next

Const EVENT_SUCCESS = 0
Set objShell = CreateObject("Wscript.Shell")
objShell.LogEvent EVENT_SUCCESS, _
    strService & " startup type has been changed."

Else

End If

