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
Noneor left empty for the current machine.-
databaseName The name of the service database or
Nonefor 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.
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