Python win32service.SERVICE_RUNNING Examples

The following are 8 code examples of win32service.SERVICE_RUNNING(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module win32service , or try the search function .
Example #1
Source File: win32serviceutil.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def ReportServiceStatus(self, serviceStatus, waitHint = 5000, win32ExitCode = 0, svcExitCode = 0):
        if self.ssh is None: # Debugging!
            return
        if serviceStatus == win32service.SERVICE_START_PENDING:
            accepted = 0
        else:
            accepted = self.GetAcceptedControls()

        if serviceStatus in [win32service.SERVICE_RUNNING,  win32service.SERVICE_STOPPED]:
            checkPoint = 0
        else:
            self.checkPoint = self.checkPoint + 1
            checkPoint = self.checkPoint

        # Now report the status to the control manager
        status = (win32service.SERVICE_WIN32_OWN_PROCESS,
                 serviceStatus,
                 accepted, # dwControlsAccepted,
                 win32ExitCode, # dwWin32ExitCode;
                 svcExitCode, # dwServiceSpecificExitCode;
                 checkPoint, # dwCheckPoint;
                 waitHint)
        win32service.SetServiceStatus( self.ssh, status) 
Example #2
Source File: win32serviceutil.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def SvcInterrogate(self):
        # Assume we are running, and everyone is happy.
        self.ReportServiceStatus(win32service.SERVICE_RUNNING) 
Example #3
Source File: win32serviceutil.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def SvcRun(self):
        self.ReportServiceStatus(win32service.SERVICE_RUNNING)
        self.SvcDoRun()
        # Once SvcDoRun terminates, the service has stopped.
        # We tell the SCM the service is still stopping - the C framework
        # will automatically tell the SCM it has stopped when this returns.
        self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) 
Example #4
Source File: platform_windows.py    From scalyr-agent-2 with Apache License 2.0 5 votes vote down vote up
def SvcDoRun(self):
        self.ReportServiceStatus(win32service.SERVICE_START_PENDING)
        try:
            self.ReportServiceStatus(win32service.SERVICE_RUNNING)
            self.log("Starting service")
            self.start()
            win32event.WaitForSingleObject(self._stop_event, win32event.INFINITE)
        except Exception as e:
            self.error(
                "Error, causing Windows Service to exit early %s" % six.text_type(e)
            )
            self.SvcStop() 
Example #5
Source File: __init__.py    From EventGhost with GNU General Public License v2.0 5 votes vote down vote up
def StartService(service):
 	  try:
 	      win32service.StartService(service, None)
 	      status = win32service.QueryServiceStatus(service)[1]
 	      while (status == win32service.SERVICE_START_PENDING):
 	          time.sleep(1)
 	          status = win32service.QueryServiceStatus(service)[1]
 	      return status == win32service.SERVICE_RUNNING
 	  except:
 	      return False 
Example #6
Source File: Create a New Admin account.py    From Python-for-Offensive-PenTest with MIT License 5 votes vote down vote up
def SvcDoRun(self):

        self.ReportServiceStatus(win32service.SERVICE_START_PENDING)
        try:
            self.ReportServiceStatus(win32service.SERVICE_RUNNING)
            self.start()            
           
        except Exception, x:
            self.SvcStop() 
Example #7
Source File: Backdoor-ing Legitmate Windows Service.py    From Python-for-Offensive-PenTest with MIT License 5 votes vote down vote up
def SvcDoRun(self): # if the signal was start - then:-

        self.ReportServiceStatus(win32service.SERVICE_START_PENDING) # tell the Service Manager that we are planing to run the serivce via reporting back a start pending status
        try:
            self.ReportServiceStatus(win32service.SERVICE_RUNNING) #tell the Service Manager that we are currently running up the service then call the start
                                                                   #function (start) if any exception happened, we will call the stop function (SvcStop)
            self.start()            
           
        except Exception, x:
            self.SvcStop() 
Example #8
Source File: platform_windows.py    From scalyr-agent-2 with Apache License 2.0 4 votes vote down vote up
def is_agent_running(self, fail_if_running=False, fail_if_not_running=False):
        """Returns true if the agent service is running, as determined by this platform implementation.

        This will optionally raise an Exception with an appropriate error message if the agent is running or not
        runnning.

        @param fail_if_running:  True if the method should raise an Exception with a platform-specific error message
            explaining how it determined the agent is running.
        @param fail_if_not_running: True if the method should raise an Exception with a platform-specific error message
            explaining how it determined the agent is not running.

        @type fail_if_running: bool
        @type fail_if_not_running: bool

        @return: True if the agent process is already running.
        @rtype: bool

        @raise AgentAlreadyRunning
        @raise AgentNotRunning
        """

        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)