#NEWLINE# def instart( cls , name , display_name = None , stay_alive = True ) : #NEWLINE# #INDENT# 'Install and  Start (auto) a Service\n\n    cls : the class (derived from Service) that implement the Service\n    name : Service name\n    display_name : the name displayed in the service manager\n    stay_alive : Service will stop on logout if False\n    ' #NEWLINE# cls . _svc_name_ = name #NEWLINE# cls . _svc_display_name_ = ( display_name or name ) #NEWLINE# try : #NEWLINE# #INDENT# module_path = modules [ cls . __module__ ] . __file__ #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# from sys import executable #NEWLINE# module_path = executable #NEWLINE# #UNINDENT# module_file = splitext ( abspath ( module_path ) ) [ 0 ] #NEWLINE# cls . _svc_reg_class_ = '{0}.{1}' . format ( module_file , cls . __name__ ) #NEWLINE# if stay_alive : #NEWLINE# #INDENT# win32api . SetConsoleCtrlHandler ( ( lambda x : True ) , True ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# win32serviceutil . InstallService ( cls . _svc_reg_class_ , cls . _svc_name_ , cls . _svc_display_name_ , startType = win32service . SERVICE_AUTO_START ) #NEWLINE# print ( 'Install ok' ) #NEWLINE# win32serviceutil . StartService ( cls . _svc_name_ ) #NEWLINE# print ( 'Start ok' ) #NEWLINE# #UNINDENT# except Exception as err : #NEWLINE# #INDENT# print ( str ( err ) )