I am attempting to use the win32service.EnumServicesStatus() function in an
win32 audit module I am working on and am having some trouble creating the
proper structure.

When I test the function with something like the following:

import win32service
import win32con

accessSCM = win32con.GENERIC_READ

hscm = win32service.OpenSCManager(None, None, accessSCM)

SCMdata = win32service.EnumServicesStatus(hscm)

print SCMdata

I get a series of outputs for all of the services within the SCM, like the
following: (u'Messenger', u'Messenger', (32, 4, 5, 0, 0, 0, 0))

So I did my homework in the Win API and found out this is the
ENUM_SERVICE_STATUS structure, basically (ServiceName, DisplayName,
ServiceStatus).  This output seems to me to indicate a tuple requiring a
matrix array (not sure how to implement in python) or something of the like.
Therefore, based on the WinAPI and other enumeration win32 functions I have
used I created the following snippet:

import win32service
import win32con

def ReportServices():
    resume = 0
    accessSCM = win32con.GENERIC_READ
    accessSrv = win32service.SC_MANAGER_ALL_ACCESS

    #Open Service Control Manager
    hscm = win32service.OpenSCManager(None, None, accessSCM)

    #Enumerate Service Control Manager DB

    typeFilter = win32service.SERVICE_WIN32
    stateFilter = win32service.SERVICE_STATE_ALL

    while 1:
        service_data, total, resume = win32service.EnumServicesStatus(hscm,
typeFilter, stateFilter, resume)
        for service in service_data:
            print service['serviceName']
            print service['displayName']
            print status
        if resume==0:
            break

ReportServices()

This particular snippet gives a Type Error, but other variations of the same
theme will produce an api_error: 'The parameter is incorrect'.  I suspect
this maybe due to the fact that all of the winAPI structures are not
implemented similar to other win32 python functions.  

Any thoughts...guidance? Thanks in advance and kudos to Hammond&Robinson's
O'Reilly Python Programming on Win32, which has gotten me this far.  An
outstanding book!

Thanks,
Bill

_______________________________________________
ActivePython mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/activepython

Reply via email to