listing existing windows services with python

Alf P. Steinbach alfps at start.no
Mon Feb 15 22:28:25 EST 2010


* alex23:
> News123 <news... at free.fr> wrote:
>> What is the best way with python to get a list of all windows services.
>>
>> As a start I would be glad to receive only the service names.
>>
>> However it would be nicer if I could get all the properties of a service
>> as well.
> 
> I highly recommend Tim Golden's fantastic WMI module[1].

It's probably Very Good, but one Microsoft-thing one should be aware of: using 
WMI functionality generally starts up a background WMI service...

Similarly, starting the standard clipboard viewer (discontinued in Windows 
Vista) starts up a silly copy-clipboard-contents-over-network service.

On a low-range machine the WMI service can be a resource concern.

I don't know whether the WMI service is a security concern (it probably is, 
considering IIS and anything Microsoft+Network and that WMI is meant to 
administrate machines over network, it's an enterprise thing not a personal 
computer user thing), but the clipboard service is, as I recall, a concern.


>     >>> import wmi
>     >>> c = wmi.WMI()
>     >>> services = c.Win32_Service()
>     >>> s = services[0]
>     >>> s
>     <_wmi_object: \\LIB-D5NYF1S\root
> \cimv2:Win32_Service.Name="Alerter">
>     >>> s.properties
>     {u'DisplayName': None, u'ServiceSpecificExitCode': None, u'State':
> None, u'Syste
>     mName': None, u'ErrorControl': None, u'Status': None,
> u'ProcessId': None, u'Desc
>     ription': None, u'Started': None, u'AcceptStop': None,
> u'CheckPoint': None, u'Pa
>     thName': None, u'WaitHint': None, u'Name': None, u'InstallDate':
> None, u'Caption
>     ': None, u'StartMode': None, u'DesktopInteract': None,
> u'ServiceType': None, u'T
>     agId': None, u'StartName': None, u'AcceptPause': None,
> u'CreationClassName': Non
>     e, u'SystemCreationClassName': None, u'ExitCode': None}
>     >>> s.Name
>     u'Alerter'
>     >>> s.Started
>     False
>     >>> s.ServiceType
>     u'Share Process'
> 
> 1: http://timgolden.me.uk/python/wmi/index.html

Cheers,

- Alf



More information about the Python-list mailing list