Problem listing services with wmi

Jean-Sébastien Guay jean_seb at videotron.ca
Tue May 17 11:49:36 EDT 2005


Hello Tim, thanks for replying,

>For your
>information, what the code is doing behind the scenes is the following:
>
><code>
>
>import win32com.client
>
>c = win32com.client.GetObject (
>  "winmgmts:{impersonationLevel=Impersonate,authenticationLevel=Default}/root/cimv2"
>)
>for service in c.ExecQuery ("SELECT * FROM Win32_Service"):
>  if service.Properties_ ("State").Value == "Stopped":
>    print service.Properties_ ("Caption").Value
>    print service.Properties_ ("State").Value
>
></code>
>  
>

Running this code seems to go through the 87 first services in the list 
returned by ExecQuery, then stops with the following error :

Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "G:\Python-2.4\Lib\site-packages\win32com\client\util.py", line 
83, in next
    return _get_good_object_(self._iter_.next())
pywintypes.com_error: (-2147217398, 'OLE error 0x8004100a', None, None)

Could there be such a thing as a "null pointer" in the list at position 
88? Or is that not possible in Python? Would the iterator just stop at a 
null value? As I said, I'm pretty new to Python so I'm just throwing 
around ideas here.

><code>
>
>set wmi = GetObject ("winmgmts:{impersonationLevel=impersonate}")
>set ServiceSet = wmi.InstancesOf ("Win32_Service")
>for each Service in ServiceSet
>   WScript.Echo Service.Description
>Next
>
></code>
>  
>

This gives me the first 87 services as well, and then stops with this 
message :

C:\Documents and Settings\guayj\Desktop\bob.vbs(7, 1) (null): 0x8004100A

So it would seem that the 3 methods give the same result. As to which 
service it has gotten to when it gets to position 88 in the list, 
obviously I can't find out with a script, and it seems that the list 
isn't in any order I can see, so I couldn't even venture a guess... I'll 
try looking if there's a service in my list that isn't valid (points to 
an uninstalled program for example) or something like that... But if you 
have other ideas please let me know.

>PS I realise that by now you've probably moved on from
>this approach, but if you did manage to pin down a problem
>we could address, I'd be very glad to address it.
>  
>

Not at all, this is a small project I'm using to try and learn Python... 
I'm currently on summer break before I start my Masters, so I have the 
luxury of keeping this on the back burner until I find a fix... Thanks 
for your help!

J-S

-- 
___________________________________________
Jean-Sébastien Guay   jean_seb at videotron.ca
             http://whitestar02.webhop.org/




More information about the Python-list mailing list