2010-12-27 24 views
6

Estoy escribiendo un servicio de python win32 a continuación son un fragmento de mi código cuando compilo el servicio que funciona, pero tengo que ir a services.msc y comenzarlo manualmente.Servicio de Python win32 comenzando automaticlly

¿Existe una opción cuando instalo el servicio por: instalación de myservice.exe, se iniciará automáticamente?

continuación se fragmento de mi código:

import win32serviceutil 
import win32service 
import win32event 

class SmallestPythonService(win32serviceutil.ServiceFramework): 
    _svc_name_ = "ser_name" 
    _svc_display_name_ = "ser_descryption" 
    #_svc_description_='ddd' 
    def __init__(self, args): 

     win32serviceutil.ServiceFramework.__init__(self, args) 
        self.hWaitStop = win32event.CreateEvent(None, 0, 0, None) 

    def SvcStop(self): 

     self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) 
     win32event.SetEvent(self.hWaitStop) 

    def SvcDoRun(self): 

     win32event.WaitForSingleObject(self.hWaitStop, win32event.INFINITE) 

if __name__=='__main__': 

    win32serviceutil.HandleCommandLine(SmallestPythonService) 

Respuesta

1

Puede utilizar sc.exe con el comando create.

sc create MyPyService binPath= "C:\myservice.exe" DisplayName= "Some Python Service" 

Más sobre esto en Microsoft KB251192.

win32serviceutil también tiene una función InstallService() es posible que pueda utilizar.

2

Me gustaría echar un vistazo a este ActiveState recipe. Es un envoltorio alrededor del win32serviceutil que muestra cómo iniciar automáticamente el servicio.

6

Utilice myservice.exe --startup=auto install para instalar el servicio y configurarlo para que se inicie automáticamente.

+0

solución Nativ es la mejor solución! – enthus1ast

0

@Maciejg no funciona para mí, aquí la solución para iniciar de forma automática mi servicio edifica de py2exe:

myservice.exe -auto -install