def is_agent_running(self, fail_if_running=False, fail_if_not_running=False):

        hscm = None
        hs = None

        try:
            hscm = win32service.OpenSCManager(None, None, win32service.SC_MANAGER_CONNECT)
            hs = win32serviceutil.SmartOpenService(hscm, _SCALYR_AGENT_SERVICE_,
                                                   win32service.SERVICE_QUERY_STATUS)
            status = win32service.QueryServiceStatusEx(hs)

            state = status['CurrentState']

            is_running = state in (win32service.SERVICE_RUNNING, win32service.SERVICE_START_PENDING)
            if fail_if_running and is_running:
                pid = status['ProcessId']
                raise AgentAlreadyRunning('The operating system reports the Scalyr Agent Service is running with '
                                          'pid=%d' % pid)
            if fail_if_not_running and not is_running:
                raise AgentNotRunning('The operating system reports the Scalyr Agent Service is not running')

            return state in (win32service.SERVICE_RUNNING, win32service.SERVICE_START_PENDING)

        finally:
            if hs is not None:
                win32service.CloseServiceHandle(hs)
            if hscm is not None:
                win32service.CloseServiceHandle(hscm)
Returns true if the agent service is running, as determined by this platform implementation.
dataset/ETHPy150Open scalyr/scalyr-agent-2/scalyr_agent/platform_windows.py/WindowsPlatformController.is_agent_running