[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

listing existing windows services with python

News123

2/16/2010 12:04:00 AM

Hi,


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.

Thanks for any info and bye


N
20 Answers

Alf P. Steinbach

2/16/2010 12:18:00 AM

0

* News123:
> Hi,
>
>
> 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.
>
> Thanks for any info and bye

* Library:

If there is some existing library for that (just search the web) then that
would probably be the easiest.

* Registry functions:

Otherwise, I'd use the general registry access functions.

Info about the registry access functions is available in your Python docs.

All the information about services is in the Windows registry (documented in
the MSDN Library, which is available in a browsable on-line version at
Microsoft).

* Text-oriented commands:

An alternative to using the registry access functions is to capture the output
of e.g. the 'sc' command.

The 'net' command also has some functionality related to services, e.g.
'net start'.


Cheers & hth.,

- Alf

alex23

2/16/2010 2:16:00 AM

0

News123 <news...@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].

>>> 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/...

Alf P. Steinbach

2/16/2010 3:28:00 AM

0

* alex23:
> News123 <news...@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/...

Cheers,

- Alf

alex23

2/16/2010 5:43:00 AM

0

On Feb 16, 1:28 pm, "Alf P. Steinbach" <al...@start.no> wrote:
> It's probably Very Good, but one Microsoft-thing one should be aware of: using
> WMI functionality generally starts up a background WMI service...

"Probably"? You haven't even used the module but you felt the need to
contribute anyway? And I see that my suggestion is "probably" a
security concern too. Would it be too much to ask for you to provide
something other than unrelated anecdotes as evidence to support these
claims? Or perhaps produce an alternative solution[1] for the OP
instead of shitting over a working solution?

So you chose to post to share your vague unsubstantiated concerns
while offering the sterling advice that a developer need be familiar
with a system in order to be aware of the costs in using it. Clearly
time well spent by all.

1: http://essiene.blogspot.com/2005/04/python-windows-ser...

Alf P. Steinbach

2/16/2010 6:05:00 AM

0

* alex23:
> On Feb 16, 1:28 pm, "Alf P. Steinbach" <al...@start.no> wrote:
>> It's probably Very Good, but one Microsoft-thing one should be aware of: using
>> WMI functionality generally starts up a background WMI service...
>
> "Probably"?

That means that since you say it's fantastic, it's probably very good.
"Probably" is a way to qualify the statement. Based on your earlier and current
quite emotional mode of expression I wouldn't take your word for an evaluation.


> You haven't even used the module but you felt the need to
> contribute anyway?

Yes, since I did not contribute about the module, but rather about the
functionality that it uses, which you didn't mention in your otherwise excellent
reply to the OP.


> And I see that my suggestion is "probably" a security concern too.

Yeah. It has nothing to do with the module, though. Only with Microsoft's WMI.


> Would it be too much to ask for you to provide
> something other than unrelated anecdotes as evidence to support these
> claims?

Google it.

E.g. <url: http://www.google.com/search?wmi+e....

Other words and search engines might turn up other things, but the description
of not a security "hole" but a security "crater" seems to me to indicate that
it's not 100% secure.


> Or perhaps produce an alternative solution[1] for the OP
> instead of shitting over a working solution?

Oh yes, the confusion that technical facts are somehow an expression of personal
feelings and social matters, and can be chosen as one pleases, hence, that
providing a fact or pointing out a possibility that is unwanted, is "shitting".

From my point of view that's stupid.

But I also think that apart from your "shitting" on me (and there the analogy is
more apt, it's not about technical facts) it's great that you provide the kind
of help that you did, pointing out a probably very good module that it seems
gives the required functionality, and giving an URL.


[snip further speculative insults]


Cheers & hth.,

- Alf

alex23

2/16/2010 8:38:00 AM

0

"Alf P. Steinbach" <al...@start.no> wrote:
> it's great that you provide the kind
> of help that you did, pointing out a probably very good module that it seems
> gives the required functionality, and giving an URL.

Yes, because that's _actually helping people_ and not just
contributing the usual self-serving pontificating nonsense that just
_flows_ from your goddamn mouth like a river of effluent
psuedotruths.

If you really wanted to help you would've cited _actual security
flaws_ in your first response to me, instead of hand waving us away
to once again do the leg work of verification. Based on your postings
here, you regularly don't have the time or inclination to back up some
of the bizarre claims you make. It would actually improve the signal
in this channel a lot if you just chose not to make those posts at all.

Alf P. Steinbach

2/16/2010 8:53:00 AM

0

* alex23:
> "Alf P. Steinbach" <al...@start.no> wrote:
>> it's great that you provide the kind
>> of help that you did, pointing out a probably very good module that it seems
>> gives the required functionality, and giving an URL.
>
> Yes, because that's _actually helping people_ and not just
> contributing the usual self-serving pontificating nonsense that just
> _flows_ from your goddamn mouth like a river of effluent
> psuedotruths.

That's an off-topic personal attack, and it's completely untrue.

You're wasting bandwidth.


> If you really wanted to help you would've cited _actual security
> flaws_ in your first response to me, instead of hand waving us away
> to once again do the leg work of verification.

Posting two ranting and raving articles complaining about 1 (one) line or so in
an earlier article, just because you personally wouldn't want to know that,
that's a total waste of the reader's time.

Disregarding the negative emotional adjectives you add everywhere, it's a good
heuristic to post what you would want to know.

I would want to know that a service is started, that it's designed for net based
administration by Microsoft, and that so it might constitute a security risk.

And so I added that information, each point of which is relevant. If you don't
want to know about the "probably" little thing you can just skim over it. If
you're unable to do that then something's wrong with you.


> Based on your postings
> here, you regularly don't have the time or inclination to back up some
> of the bizarre claims you make. It would actually improve the signal
> in this channel a lot if you just chose not to make those posts at all.

That an off-topic personal attack, and it's completely untrue.

Another poster (not me) has described you in an article here as a sockpuppet
(false identity being in reality another poster here) and a troll; I believe at
least the troll bit.

It would reduce the noise level a bit if you stopped contributing noise like above.


Cheers,

- Alf

Ben Finney

2/16/2010 9:05:00 AM

0

alex23 <wuwei23@gmail.com> writes:

> Yes, because that's _actually helping people_ and not just
> contributing the usual self-serving pontificating nonsense that just
> _flows_ from your goddamn mouth like a river of effluent psuedotruths.

I can't see what improvement you hope to achieve by sending something
like this. If, instead, you just want to vent cathartically, this isn't
the place to do it.

Please, don't send the above kind of vitriol to this public forum.
Better yet, compose it in your editor, bask in what you've written, then
delete it unsent.

--
\ â??Kill myself? Killing myself is the last thing I'd ever do.â? |
`\ â??Homer, _The Simpsons_ |
_o__) |
Ben Finney

News123

2/16/2010 12:18:00 PM

0

Thanks for your answers,




The security wouldn't be a concern, as I would run while being only
accessible by trusted hosts.

I don't use the script often, so if it would start a WMI service during
runtime and stop it afterwards it would be fine.

I just wonder whether installing another 3rd party package for just
listing all services s worth the effort.


In my current case I'll go probably for parsing the output of
"sc.exe query" or I'll traverse the registry.

currently I just want to get a list of the names of the running services.


bye


N



Alf P. Steinbach wrote:
> * alex23:
>> News123 <news...@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/...
>
> Cheers,
>
> - Alf

Tim Golden

2/16/2010 12:30:00 PM

0

On 16/02/2010 12:18, News123 wrote:
> I don't use the script often, so if it would start a WMI service during
> runtime and stop it afterwards it would be fine.

FWIW -- your other considerations notwithstanding -- I'm not aware
of WMI having this effect. Generally you can assume that the WMI
services are running (or not, if someone's shut them off) but
I've never heard of them being started up by virtue of a call
to the WMI subsystem and then stopped afterwards.

That said, I'd be interested if someone did have a pointer for this;
worth putting a caveat in the docs if that were the case.

TJG