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

Connecting to the SCM

Most of the Win32 API for working with services requires a handle to the SCM. This is obtained by the function win32service.OpenSCManager() .

handle = win32service.OpenSCManager(machineName, databaseName, access)
machineName

The name of the machine on which you wish to open the SCM. This can be None or left empty for the current machine.

databaseName

The name of the service database or None for the default. The default is almost always used.

access

The desired access on the SCM.

The result is a handle to the SCM. Once you are finished with the handle, the function win32service.CloseServiceHandle() is used. See Appendix B, for a complete description of these functions.

To open the SCM on the current machine, we could use the following code:

>>> import win32service
>>> hscm=win32service.OpenSCManager(None, None, win32service.SC_MANAGER_ALL_ACCESS)
>>> hscm
1368896
>>>

As you can see, service handles are implemented as integers, although this may be changed to a variation of a PyHANDLE object.

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