Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. import win32serviceutil, win32service
  2. import win32event, win32api
  3. import servicemanager
  4. import time
  5.  
  6. import win32gui, win32gui_struct, win32con
  7.  
  8. class EventDemoService(win32serviceutil.ServiceFramework):
  9. _svc_name_ = "PyServiceEventDemo"
  10. _svc_display_name_ = "Python Service Event Demo"
  11. _svc_description_ = "Demonstrates a Python service which takes
  12. advantage of the extra notifications"
  13. def __init__(self, args):
  14. win32serviceutil.ServiceFramework.__init__(self, args)
  15. self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
  16. self.running = True
  17. def SvcStop(self):
  18. self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
  19. win32event.SetEvent(self.hWaitStop)
  20. self.running = False
  21. def SvcDoRun(self):
  22. self.ReportServiceStatus(win32service.SERVICE_RUNNING)
  23. while self.running:
  24. servicemanager.LogInfoMsg("aservice - is alive and well")
  25. time.sleep(3)
  26. def ctrlHandler(ctrlType):
  27. return True
  28.  
  29. if __name__=='__main__':
  30. win32api.SetConsoleCtrlHandler(ctrlHandler, True)
  31. win32serviceutil.HandleCommandLine(EventDemoService)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement