franck34 bqomrvliagmailcom warning setuppy require cmdline_stylepywin32 usage serviceexe install serviceexe start serviceexe stop serviceexe remove see output program running python sitepackageswin32libwin32traceutil setuppy distutilscore import setup import py2exe class target def __init__self kw self__dict__updatekw versioninfo resources selfversion 050 selfcompany_name company selfcopyright copyright selfname py2exe sample files myservice target description foo modules service cmdline_stylepywin32 setup options py2exe compressed 1 bundle_files 1 consoleservicepy zipfile none servicemyservice import win32service import win32serviceutil import win32event import win32evtlogutil import win32traceutil import time import sys class aservicewin32serviceutilserviceframework _svc_name_ aservice _svc_display_name_ aservice nothing _svc_deps_ eventlog def __init__selfargs win32serviceutilserviceframework__init__selfargs selfhwaitstopwin32eventcreateeventnone 0 0 none selfisalivetrue def svcstopself tell service manager trying stop required selfreportservicestatuswin32serviceservice_stop_pending write message sm optional import servicemanager servicemanagerloginfomsgaservice recieved stop signal set event call win32eventseteventselfhwaitstop selfisalivefalse def svcdorunself import servicemanager write started event event log required win32evtlogutilreporteventself_svc_name_servicemanagerpys_service_started0 servicemanagereventlog_information_typeself_svc_name_ methode 1 wait beeing stopped win32eventwaitforsingleobjectselfhwaitstop win32eventinfinite methode 2 wait beeing stopped selftimeout1000 milliseconds update every second selfisalive wait service stop signal timeout loop rcwin32eventwaitforsingleobjectselfhwaitstop selftimeout print looping write stopped event event log required win32evtlogutilreporteventself_svc_name_servicemanagerpys_service_stopped0 servicemanagereventlog_information_typeself_svc_name_ selfreportservicestatuswin32serviceservice_stopped return __name__ __main__ win32serviceutilhandlecommandlineaservice thu 07 aug 2008 151656 0200 py2exeusers py2exe sample windows service working tested