Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > listing existing windows services with python

Reply
Thread Tools

listing existing windows services with python

 
 
News123
Guest
Posts: n/a
 
      02-16-2010
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
 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      02-16-2010
* 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
 
Reply With Quote
 
 
 
 
alex23
Guest
Posts: n/a
 
      02-16-2010
News123 <(E-Mail Removed)> 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/index.html
 
Reply With Quote
 
Alf P. Steinbach
Guest
Posts: n/a
 
      02-16-2010
* alex23:
> News123 <(E-Mail Removed)> 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
 
Reply With Quote
 
alex23
Guest
Posts: n/a
 
      02-16-2010
On Feb 16, 1:28*pm, "Alf P. Steinbach" <(E-Mail Removed)> 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/...-services.html
 
Reply With Quote
 
Alf P. Steinbach
Guest
Posts: n/a
 
      02-16-2010
* alex23:
> On Feb 16, 1:28 pm, "Alf P. Steinbach" <(E-Mail Removed)> 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+exploit>.

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
 
Reply With Quote
 
alex23
Guest
Posts: n/a
 
      02-16-2010
"Alf P. Steinbach" <(E-Mail Removed)> 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.
 
Reply With Quote
 
Alf P. Steinbach
Guest
Posts: n/a
 
      02-16-2010
* alex23:
> "Alf P. Steinbach" <(E-Mail Removed)> 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
 
Reply With Quote
 
News123
Guest
Posts: n/a
 
      02-16-2010
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 <(E-Mail Removed)> 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

 
Reply With Quote
 
Tim Golden
Guest
Posts: n/a
 
      02-16-2010
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Existing Dll - using Functions from an existing dll Tristin.Colby@gmail.com Ruby 0 02-05-2008 07:38 PM
Why no existing Java type to existing XML schema binding support? nrm Java 3 04-10-2006 04:52 PM
Re: Problem listing services with wmi =?ISO-8859-1?Q?Jean-S=E9bastien_Guay?= Python 0 05-17-2005 03:49 PM
Problem listing services with wmi =?ISO-8859-1?Q?Jean-S=E9bastien_Guay?= Python 5 05-16-2005 09:45 PM
Integrating with eBay listing/bidding services LP ASP .Net 1 02-19-2005 08:26 PM



Advertisments