Utility Functions to Simplify Working with Services
While working with the SCM is
not difficult, it’s a little tedious dealing with the handles
and the SCM. To this end, the
win32serviceutil
module attempts to make simple
interactions with services quicker and easier. The module is poorly
documented, so some of the functions are discussed here:
-
status = StopService(serviceName,machine=None): Stops the named service on the specified machine. For example, to stop the messenger service on the computer named skippy :
>>> win32serviceutil.StopService("Messenger", "skippy") (32, 3, 0, 0, 0, 6, 20000) >>> .The result is the same as from the
win32service.StopService()function described previously in this chapter.-
StopServiceWithDeps (serviceName,machine=None,waitSecs=30): Similar to
StopService, but stops the named service after stopping all dependant services. This function waitswaitSecsfor each service to stop.-
StartService(serviceName,args=None,machine=None): Starts the named service on the specified machine, with the specified arguments. For example, to start the messenger service on the computer named skippy:
>>> win32serviceutil.StartService("Messenger", None, "skippy") >>>-
RestartService(serviceName,args=None,waitSeconds=30,machine= None): If the service is already running, stops the service and waits
waitSecondsfor the stop process to complete. Then it starts the service with the specified arguments. This is used mainly for debugging services, where ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access