[python-win32] mapping from a service to its class file?
Bill Janssen
janssen at parc.com
Sun May 9 20:31:16 CEST 2010
Bill Janssen <janssen at parc.com> wrote:
> For the [services] that are using PythonService.exe, I'd like to check
> to see whether the Python module for the service is still present. Is
> there any way to retrieve the information about that from the service?
Here's what I came up with:
import sys, os, win32api, win32con, win32service
services = {}
mgr = win32service.OpenSCManager(None, None, 4)
try:
svcinfo = win32service.EnumServicesStatus(mgr)
for svc in svcinfo:
svch = win32service.OpenService(mgr, svc[0], win32service.SERVICE_QUERY_CONFIG)
try:
config = win32service.QueryServiceConfig(svch)
if config[3].endswith('PythonService.exe"'):
klass = win32api.RegQueryValue(
win32con.HKEY_LOCAL_MACHINE,
"System\\CurrentControlSet\\Services\\%s\\PythonClass" % (svc[0],))
classfile = os.path.splitext(klass)[0] + ".py"
sys.stdout.write("%s %s\n" % (svc[0], os.path.exists(classfile))
finally:
win32service.CloseServiceHandle(svch)
finally:
win32service.CloseServiceHandle(mgr)
Bill
More information about the python-win32
mailing list