Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 19th, 2005, 02:20 AM
Jean-Sébastien Guay
Guest
 
Posts: n/a
Default 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 jean_seb@videotron.ca
http://whitestar02.webhop.org/

  #2  
Old July 19th, 2005, 02:20 AM
Larry Bates
Guest
 
Posts: n/a
Default Re: Problem listing services with wmi

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:[color=blue]
> 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
>[/color]
  #3  
Old July 19th, 2005, 02:20 AM
Larry Bates
Guest
 
Posts: n/a
Default Re: Problem listing services with wmi

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:[color=blue]
> 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
>[/color]

  #4  
Old July 19th, 2005, 02:20 AM
Jean-Sébastien Guay
Guest
 
Posts: n/a
Default Re: Problem listing services with wmi

Hello Larry,
[color=blue]
>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():
>
>[/color]

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 jean_seb@videotron.ca
http://whitestar02.webhop.org/

  #5  
Old July 19th, 2005, 02:20 AM
Larry Bates
Guest
 
Posts: n/a
Default Re: Problem listing services with wmi

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:[color=blue]
> Hello Larry,
>[color=green]
>> 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():
>>
>>[/color]
>
> 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
>[/color]
  #6  
Old July 19th, 2005, 02:20 AM
Roger Upole
Guest
 
Posts: n/a
Default Re: Problem listing services with wmi

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" <jean_seb@videotron.ca> wrote in message
news:mailman.59.1116271963.8733.python-list@python.org...[color=blue]
> 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 jean_seb@videotron.ca
> http://whitestar02.webhop.org/
>[/color]




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

Bookmarks

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles