def instart(cls, name, display_name=None, stay_alive=True):
 cls._svc_name_ = name
 cls._svc_display_name_ = (display_name or name)
 try:
  module_path = modules[cls.__module__].__file__
 except AttributeError:
  from sys import executable
  module_path = executable
 module_file = splitext(abspath(module_path))[0]
 cls._svc_reg_class_ = '{0}.{1}'.format(module_file, cls.__name__)
 if stay_alive:
  win32api.SetConsoleCtrlHandler((lambda x: True), True)
 try:
  win32serviceutil.InstallService(cls._svc_reg_class_, cls._svc_name_, cls._svc_display_name_, startType=win32service.SERVICE_AUTO_START)
  print('Install ok')
  win32serviceutil.StartService(cls._svc_name_)
  print('Start ok')
 except Exception as err:
  print(str(err))

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