Use of win32service.EnumServicesStatus() 
Author Message
 Use of win32service.EnumServicesStatus()

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



Tue, 20 May 2003 03:00:00 GMT  
 Use of win32service.EnumServicesStatus()

Quote:

> 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))

Yes - that is all you need!  You have a multi-dimensional sequence.  Eg:

statuses = win32service.EnumServicesStatus(hscm, typeFilter, stateFilter)
     for (short_name, desc, status) in statuses:
         print short_name, desc, status

(where "status" itself is a tuple that can be unpacked.

Hope this helps...

Mark.



Wed, 21 May 2003 09:06:59 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Win32service.EnumServicesStatus

2. ----------------------------------------------------*Question*-------------------------------------------------------------------------

3. second_hand-new_2003_year?-NO!-Send_FREE-_-RUSSIA_614104_PERM_MOLDAVAN_4_OF_11_GLOBA_IVAN_expenses pay!_LOT_GRUISE_RUSSIA_YOUR

4. +++GET YOUR FREE PENTIUM CELERON-300+++____________________________________________________________________________________________e45u89et rijeetoeirtj erioyopwij45o rtio

5. SCAM Re: +++GET YOUR FREE PENTIUM CELERON-300+++____________________________________________________________________________________________ertopi4509foi eroirtjyiort iryhwoiuri r

6. +++GET YOUR FREE PENTIUM CELERON-300+++____________________________________________________________________________________________e45u89et rijeetoeirtj erioyopwij45o rtio

 

 
Powered by phpBB® Forum Software