O'Reilly logo

Python Programming On Win32 by Mark Hammond, Andy Robinson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 waits waitSecs for 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 waitSeconds for the stop process to complete. Then it starts the service with the specified arguments. This is used mainly for debugging services, where ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required