Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import win32serviceutil
- class StopStartService:
- STARTED, STOPPED = 4, 1
- def __init__(self, service_name, timeout=5):
- self.service_name = service_name
- self.timeout = timeout
- def __enter__(self):
- self._enter_if_not(win32serviceutil.StopService, StopStartService.STOPPED)
- def __exit__(self, exc_type, exc_val, exc_tb):
- self._enter_if_not(win32serviceutil.StartService, StopStartService.STARTED)
- def _enter_if_not(self, f, status):
- if win32serviceutil.QueryServiceStatus(self.service_name)[1] != status:
- f(self.service_name)
- win32serviceutil.WaitForServiceStatus(storis_service_name, status, self.timeout)
Add Comment
Please, Sign In to add comment