title: Python Windows Service - Not responding to start/stop from built exe (but works in python)
body: <p>This is my first time building a windows service, and I thought I had it working. Installing as <code>python aservice.py install</code>  works fine, and responds accordingly.</p>
  
  <p>However, since the machines that I will need to install this service on, will not have python installed, I wanted to build it into an executable, that can install the service. Although the executable is successful in installing the service, When I try to start it either manually, or through <code>net start</code> or <code>sc start</code> The service does not respond.</p>
  
  <p>Starting manually returns - Error 1053: The Service did not respond to the start or control request in a timely fashion.</p>
  
  <p>Net Start returns - The Service did not respond to the control function.</p>
  
  <p>When installed with python, it responds to all commands, and works fine. Not sure what is happening during the build process, but I am obviously missing something</p>
  
  <p>Using Python 3.4 64 bit. All boxes that need the service, will also be 64 bit. </p>
  
  <h2>Service Definition</h2>
  
  <pre><code>class aservice(win32serviceutil.ServiceFramework):
  
     _svc_name_ = "Test Login Service"
     _svc_display_name_ = "Test Login Service"
     _svc_description_ = "Test"
  
     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):
        import servicemanager      
        servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,servicemanager.PYS_SERVICE_STARTED,(self._svc_name_, '')) 
  
        self.timeout = 3000
  
        while 1:
           # Wait for service stop signal, if I timeout, loop again
           rc = win32event.WaitForSingleObject(self.hWaitStop, self.timeout)
           # Check to see if self.hWaitStop happened
           if rc == win32event.WAIT_OBJECT_0:
              # Stop signal encountered
              servicemanager.LogInfoMsg("aservice - STOPPED")
              break
           else:
              servicemanager.LogInfoMsg("aservice - is alive and well")
  
               ...Doing Things...
  
              servicemanager.LogInfoMsg("Logon Service Has Completed, Stopping")
              time.sleep(10)   
              break
  
  def ctrlHandler(ctrlType):
     return True
  
  if __name__ == '__main__':   
     win32api.SetConsoleCtrlHandler(ctrlHandler, True)   
     win32serviceutil.HandleCommandLine(aservice)
  </code></pre>
  
  <h2>setup.py</h2>
  
  <pre><code>`from distutils.core import setup 
  import py2exe 
  
  
  # setup.py 
  
  # 
  class Target: 
      def __init__(self, **kw): 
          self.__dict__.update(kw) 
          # for the versioninfo resources 
          self.version = "0.5.0" 
          self.company_name = "Company" 
          self.copyright = "no copyright" 
          self.name = "Test22" 
  
  
  myservice = Target( 
      description = 'Edit Logon Service', 
      modules = ['Logon_Service'], 
      cmdline_style='pywin32' 
      ) `
  </code></pre>
  
  <p>build command = <code>python setup.py py2exe</code></p>
  
  <p>I have tried setup.py with windows also, that works the same, but doesnt print console logs. </p>
  
  <p>Any ideas how I can properly install this service on computers that dont have python? </p>
  
  <p>Edit: setup.py working</p>