# ts1.py
#   Test service
#

import win32serviceutil
import win32service
import win32event

class TService(win32serviceutil.ServiceFramework):
    _svc_name_ = "TestService"
    _svc_display_name_ = "Test Service"
    def __init__(self, args):
        win32serviceutil.ServiceFramework.__init__(self, args)
        self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)

    def SvcDoRun(self):
        # write start log message
        import servicemanager
        servicemanager.LogMsg(
            servicemanager.EVENTLOG_INFORMATION_TYPE,
            servicemanager.PYS_SERVICE_STARTED,
            (self._svc_name_, ''))

        message = "test 000002"
        servicemanager.LogInfoMsg(message)

        #
        # here you go
        #
        win32event.WaitForSingleObject(self.hWaitStop, win32event.INFINITE)

        # write stop log message
        servicemanager.LogMsg(
            servicemanager.EVENTLOG_INFORMATION_TYPE,
            servicemanager.PYS_SERVICE_STOPPED,
            (self._svc_name_, ''))


    def SvcStop(self):
        self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
        win32event.SetEvent(self.hWaitStop)


if __name__ == '__main__':
    win32serviceutil.HandleCommandLine(TService)



to register the service:
myservice.py install

You can find more on writting Windows Services in Python in Mark Hammond's
book Python Programming on Win32

Cheers
Andrew

----- Original Message -----
From: "Robin Siebler" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, June 21, 2001 2:42 PM
Subject: How to start/stop/check a service


> I'm new to Python.  Could someone give me an example of how to start or
stop
> a service?
>
> Thanks!
>
> Robin L. Siebler
> Software Test Engineer
> iBeam
> --------------------------------
> "Bother", said Pooh, as he deleted  Windows.
>
> _______________________________________________
> ActivePython mailing list
> [EMAIL PROTECTED]
> http://listserv.ActiveState.com/mailman/listinfo/activepython
>

_______________________________________________
ActivePython mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/activepython

Reply via email to