Jump to content

Monitoring a system service


Recommended Posts

Could someone please tell me if you can monitor a windows service.

I need to be able to tell if the service is STOPPED or STARTED at any

given point in time and then do something depending on the state.

Thanks in advance

Link to comment
Share on other sites

  • Moderators

Could someone please tell me if you can monitor a windows service.

I need to be able to tell if the service is STOPPED or STARTED at any

given point in time and then do something depending on the state.

Thanks in advance

Search the forum, there was something on this in the last month or so I believe.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

;returns 4 if running
;beta only
$servicename = 'wuauserv'; example windows updates

$stdout = Run('sc.exe query ' & $servicename, '', @SW_HIDE, 2)
$data = _StdOut($stdout)

Func _StdOut($stdout)
    Local $data
    While 1
        $data = StdOutRead($stdout)
        If @error Then Return 'unknown'
        If $data Then
            $data = StringStripWS($data, 4)
            Select
                Case StringInStr($data, 'STATE : 1')
                    Return '1'
                Case StringInStr($data, 'STATE : 2')
                    Return '2'
                Case StringInStr($data, 'STATE : 3')
                    Return '3'
                Case StringInStr($data, 'STATE : 4')
                    Return 'Running'
                Case Else
                    Return 'unknown'
            EndSelect
        Else
            Sleep(100)
        EndIf
    WEnd
EndFunc

MsgBox(0, '', $data)

i don't know who wrote this code, i did not.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...