Problem listing services with wmi

Roger Upole rupole at hotmail.com
Mon May 16 17:45:44 EDT 2005


The only thing I could find for the hresult is that it corresponds to
wbemErrCriticalError.  According to this page
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/wbemerrorenum.asp
it's some kind of internal error.

        Roger


"Jean-Sébastien Guay" <jean_seb at videotron.ca> wrote in message 
news:mailman.59.1116271963.8733.python-list at 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/comp.lang.python/browse_thread/thread/19fa91ea1a1ff160/0364b7cd22d73483?q=WMI_EXCEPTIONS&rnum=1#0364b7cd22d73483) 
> 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 at 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 =---



More information about the Python-list mailing list