How to check if a windows 7 service is active from IWS?

Hello,

A large automotive customer have a need, they have a server running a application for traceability across the full plant, but sometimes does not start automatically, they want a signal tower that shows the application or service state, green light = service/application running, red = service/application stopped. Is there a IWS funtion to check is service is running? either local or remote?

Regards

Cruz Castillo
Parents
  • Hi Cruz,

    I'm not sure if you can do this with in-built IWS functions, but it certainly looks like you can do it in VBS. Try this link:

    Services

    which includes the following extracts:

    ===========================================
    Set objComputer = GetObject("WinNT://computername,computer")
    objComputer.Filter = Array("Service")

    strServiceName = "blaablaa"

    For Each aService In objComputer
    If LCase(strServiceName) = LCase(aService.Name) Then
    Wscript.Echo aService.Name & "=" & aService.Status
    End If
    Next


    or to bind directly to a service

    Set objComputer = GetObject("WinNT://computername,computer")
    Set objService = objCOmputer.GetObject("service", "blaablaa")
    Msgbox objService.Name & objService.Status

    the .Filter can set set to any class the computer object contains


    the second will throw an error if the service doesnt exist, so you can be defensive with the iteration (i.e. first example) or you can wrap in On Error Resume Next and trap the Err.Number

    the .Filter is literally a 'Filter'.
    you are filtering on "service"'s so after applying the 'Filter' on the Computer object it only contains service objects for the For Each to loop through

    ===========================================

    Regards,
    Greg Shearer
Reply
  • Hi Cruz,

    I'm not sure if you can do this with in-built IWS functions, but it certainly looks like you can do it in VBS. Try this link:

    Services

    which includes the following extracts:

    ===========================================
    Set objComputer = GetObject("WinNT://computername,computer")
    objComputer.Filter = Array("Service")

    strServiceName = "blaablaa"

    For Each aService In objComputer
    If LCase(strServiceName) = LCase(aService.Name) Then
    Wscript.Echo aService.Name & "=" & aService.Status
    End If
    Next


    or to bind directly to a service

    Set objComputer = GetObject("WinNT://computername,computer")
    Set objService = objCOmputer.GetObject("service", "blaablaa")
    Msgbox objService.Name & objService.Status

    the .Filter can set set to any class the computer object contains


    the second will throw an error if the service doesnt exist, so you can be defensive with the iteration (i.e. first example) or you can wrap in On Error Resume Next and trap the Err.Number

    the .Filter is literally a 'Filter'.
    you are filtering on "service"'s so after applying the 'Filter' on the Computer object it only contains service objects for the For Each to loop through

    ===========================================

    Regards,
    Greg Shearer
Children
No Data