none
script to find stopped services. RRS feed

  • Question

  • I am trying to find any services that are set to automatic that are stopped to alert to scom. If the service is set to automatic(delayed startup) i want to ignore these ones. It seems when I try to use the DelayedAutoStart variable under the Win32_service variable it give me an error as follows:

    C:\Temp\test.vbs(12, 2) Microsoft VBScript runtime error: Object doesn't support
     this property or method: 'DelayedAutoStart'

    here is my script:

    'Declare Variables
    Dim objWMIService, objProcess, colProcess, Status, strComputer, strService, oAPI, oBag
     
    Status= true
    strComputer = "."  
    Set oAPI = CreateObject("MOM.ScriptAPI")
    Set oBag=  oAPI.CreatePropertyBag()
    Set objWMIService = GetObject("winmgmts:"& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
    Set colProcess = objWMIService.ExecQuery ("SELECT * FROM Win32_Service ")
     
    For Each objProcess in colProcess
     if  (objProcess.StartMode="Auto") and (objProcess.state <> "Running") and  (objProcess.DelayedAutoStart <> 0) then
      'message=message & objProcess.DisplayName  & " " & objProcess.State  & " " & objProcess.StartMode & vblf & vbcr 
      status=false
      call oBag.AddValue("Status","NOT OK")
      call oBag.AddValue("Service",objProcess.DisplayName)
      Exit For
      End If
    Next
    if status=True then
     call oBag.AddValue("status","OK")
    end if
    call oBag.AddValue("status","OK")
    call oAPI.return(obag)

    Saturday, November 18, 2017 8:03 PM

Answers

All replies