470,810 Members | 855 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,810 developers. It's quick & easy.

Problem listing services with wmi

Hello,

I'm pretty new to Python, though I have a fair bit of experience with
C/C++, Java, Perl, PHP and others.

I installed Tim Golden's wmi module
(http://tgolden.sc.sabren.com/python/wmi.html), in the hopes it would
help me list and work with services on my Win32 machine. Now, everything
seems fine except for one thing : Listing services!

I tried running a couple of the examples on Tim's more examples page in
the python shell (for example, List all running processes, Show the
percentage free space for each fixed disk, Show the IP and MAC addresses
for IP-enabled network interfaces, etc.) and they worked fine. But when
I try to run the first example which is on the first page above, I get
an error. The code is :

import wmi

c = wmi.WMI ()
for s in c.Win32_Service ():
if s.State == 'Stopped':
print s.Caption, s.State
and I get :

Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "G:\Python-2.4\Lib\site-packages\wmi.py", line 404, in __call__
return self.wmi.query (wql)
File "G:\Python-2.4\Lib\site-packages\wmi.py", line 583, in query
raise WMI_EXCEPTIONS.get (hresult, x_wmi (hresult))
wmi.x_wmi: -2147217398

(the exception seems to be thrown on the "for s in..." line)
I have only found one discussion in this newsgroup's archives that seems
to talk about this problem
(http://groups-beta.google.com/group/...64b7cd22d73483)
and the fix they suggest there (calling pythoncom.CoInitialize () before
instantiating the WMI object) doesn't seem to work in this case. In
other words, this code :

import wmi
import pythoncom

pythoncom.CoInitialize ()
c = wmi.WMI ()
for s in c.Win32_Service ():
if s.State == 'Stopped':
print s.Caption, s.State

gives me the same result as above.

Could someone please point me in the right direction to find out what's
wrong?

Thanks in advance,

J-S

--
___________________________________________
Jean-Sébastien Guay je******@videotron.ca
http://whitestar02.webhop.org/

Jul 19 '05 #1
5 3030
Might not be the problem but try without the leading
spaces before your method calls.

for s in c.Win32_Service ():

should be

for s in c.Win32_Service():

-Larry
Jean-Sébastien Guay wrote:
Hello,

I'm pretty new to Python, though I have a fair bit of experience with
C/C++, Java, Perl, PHP and others.

I installed Tim Golden's wmi module
(http://tgolden.sc.sabren.com/python/wmi.html), in the hopes it would
help me list and work with services on my Win32 machine. Now, everything
seems fine except for one thing : Listing services!

I tried running a couple of the examples on Tim's more examples page in
the python shell (for example, List all running processes, Show the
percentage free space for each fixed disk, Show the IP and MAC addresses
for IP-enabled network interfaces, etc.) and they worked fine. But when
I try to run the first example which is on the first page above, I get
an error. The code is :

import wmi

for s in c.Win32_Service ():
if s.State == 'Stopped':
print s.Caption, s.State
and I get :

Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "G:\Python-2.4\Lib\site-packages\wmi.py", line 404, in __call__
return self.wmi.query (wql)
File "G:\Python-2.4\Lib\site-packages\wmi.py", line 583, in query
raise WMI_EXCEPTIONS.get (hresult, x_wmi (hresult))
wmi.x_wmi: -2147217398

(the exception seems to be thrown on the "for s in..." line)
I have only found one discussion in this newsgroup's archives that seems
to talk about this problem
(http://groups-beta.google.com/group/...64b7cd22d73483)
and the fix they suggest there (calling pythoncom.CoInitialize () before
instantiating the WMI object) doesn't seem to work in this case. In
other words, this code :

import wmi
import pythoncom

pythoncom.CoInitialize ()
c = wmi.WMI ()
for s in c.Win32_Service ():
if s.State == 'Stopped':
print s.Caption, s.State

gives me the same result as above.

Could someone please point me in the right direction to find out what's
wrong?

Thanks in advance,

J-S

Jul 19 '05 #2
Might not be the problem but try without the leading
spaces before your method calls.

for s in c.Win32_Service ():

should be

for s in c.Win32_Service():

-Larry
Jean-Sébastien Guay wrote:
Hello,

I'm pretty new to Python, though I have a fair bit of experience with
C/C++, Java, Perl, PHP and others.

I installed Tim Golden's wmi module
(http://tgolden.sc.sabren.com/python/wmi.html), in the hopes it would
help me list and work with services on my Win32 machine. Now, everything
seems fine except for one thing : Listing services!

I tried running a couple of the examples on Tim's more examples page in
the python shell (for example, List all running processes, Show the
percentage free space for each fixed disk, Show the IP and MAC addresses
for IP-enabled network interfaces, etc.) and they worked fine. But when
I try to run the first example which is on the first page above, I get
an error. The code is :

import wmi

for s in c.Win32_Service ():
if s.State == 'Stopped':
print s.Caption, s.State
and I get :

Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "G:\Python-2.4\Lib\site-packages\wmi.py", line 404, in __call__
return self.wmi.query (wql)
File "G:\Python-2.4\Lib\site-packages\wmi.py", line 583, in query
raise WMI_EXCEPTIONS.get (hresult, x_wmi (hresult))
wmi.x_wmi: -2147217398

(the exception seems to be thrown on the "for s in..." line)
I have only found one discussion in this newsgroup's archives that seems
to talk about this problem
(http://groups-beta.google.com/group/...64b7cd22d73483)
and the fix they suggest there (calling pythoncom.CoInitialize () before
instantiating the WMI object) doesn't seem to work in this case. In
other words, this code :

import wmi
import pythoncom

pythoncom.CoInitialize ()
c = wmi.WMI ()
for s in c.Win32_Service ():
if s.State == 'Stopped':
print s.Caption, s.State

gives me the same result as above.

Could someone please point me in the right direction to find out what's
wrong?

Thanks in advance,

J-S


Jul 19 '05 #3
Hello Larry,
Might not be the problem but try without the leading
spaces before your method calls.

for s in c.Win32_Service ():

should be

for s in c.Win32_Service():


No change. For reference, the reason I know it's the c.Win32_Service()
call that's throwing the exception is that if I try to run this :

import wmi
import pythoncom

pythoncom.CoInitialize()
c = wmi.WMI()
services = c.Win32_Service()
for s in services :
print s.Caption, s.State

the exception gets thrown on the "services = ..." line.

Out of curiosity, is there any reason why whitespace between the method
name and parameter list parentheses isn't good? Because the code I
posted before was copy-pasted from Tim Golden's site
(http://tgolden.sc.sabren.com/python/wmi.html) and the spaces were there.

Thanks,

J-S

--
___________________________________________
Jean-Sébastien Guay je******@videotron.ca
http://whitestar02.webhop.org/

Jul 19 '05 #4
I guess I was wrong and it does work, but from Python Style Guide:

Whitespace in Expressions and Statements
Pet Peeves

Guido hates whitespace in the following places:

<snip>
- Immediately before the open parenthesis that starts the argument
list of a function call, as in "spam (1)". Always write
this as "spam(1)".

<end snip>

-Larry

Jean-Sébastien Guay wrote:
Hello Larry,
Might not be the problem but try without the leading
spaces before your method calls.

for s in c.Win32_Service ():

should be

for s in c.Win32_Service():


No change. For reference, the reason I know it's the c.Win32_Service()
call that's throwing the exception is that if I try to run this :

import wmi
import pythoncom

pythoncom.CoInitialize()
c = wmi.WMI()
services = c.Win32_Service()
for s in services :
print s.Caption, s.State

the exception gets thrown on the "services = ..." line.

Out of curiosity, is there any reason why whitespace between the method
name and parameter list parentheses isn't good? Because the code I
posted before was copy-pasted from Tim Golden's site
(http://tgolden.sc.sabren.com/python/wmi.html) and the spaces were there.

Thanks,

J-S

Jul 19 '05 #5
The only thing I could find for the hresult is that it corresponds to
wbemErrCriticalError. According to this page
http://msdn.microsoft.com/library/de...merrorenum.asp
it's some kind of internal error.

Roger
"Jean-Sébastien Guay" <je******@videotron.ca> wrote in message
news:ma************************************@python .org...
Hello,

I'm pretty new to Python, though I have a fair bit of experience with
C/C++, Java, Perl, PHP and others.

I installed Tim Golden's wmi module
(http://tgolden.sc.sabren.com/python/wmi.html), in the hopes it would help
me list and work with services on my Win32 machine. Now, everything seems
fine except for one thing : Listing services!

I tried running a couple of the examples on Tim's more examples page in
the python shell (for example, List all running processes, Show the
percentage free space for each fixed disk, Show the IP and MAC addresses
for IP-enabled network interfaces, etc.) and they worked fine. But when I
try to run the first example which is on the first page above, I get an
error. The code is :

import wmi

c = wmi.WMI ()
for s in c.Win32_Service ():
if s.State == 'Stopped':
print s.Caption, s.State
and I get :

Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "G:\Python-2.4\Lib\site-packages\wmi.py", line 404, in __call__
return self.wmi.query (wql)
File "G:\Python-2.4\Lib\site-packages\wmi.py", line 583, in query
raise WMI_EXCEPTIONS.get (hresult, x_wmi (hresult))
wmi.x_wmi: -2147217398

(the exception seems to be thrown on the "for s in..." line)
I have only found one discussion in this newsgroup's archives that seems
to talk about this problem
(http://groups-beta.google.com/group/...64b7cd22d73483)
and the fix they suggest there (calling pythoncom.CoInitialize () before
instantiating the WMI object) doesn't seem to work in this case. In other
words, this code :

import wmi
import pythoncom

pythoncom.CoInitialize ()
c = wmi.WMI ()
for s in c.Win32_Service ():
if s.State == 'Stopped':
print s.Caption, s.State

gives me the same result as above.

Could someone please point me in the right direction to find out what's
wrong?

Thanks in advance,

J-S

--
___________________________________________
Jean-Sébastien Guay je******@videotron.ca
http://whitestar02.webhop.org/



----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Jul 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by fripper | last post: by
3 posts views Thread by Microsoft Newsgroups | last post: by
12 posts views Thread by Joel Byrd | last post: by
reply views Thread by Stewart Midwinter | last post: by
1 post views Thread by infiniti | last post: by
2 posts views Thread by Lionel B | last post: by
6 posts views Thread by Saqib Ali | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.