[Jean-Sébastien Guay] | | 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! | | 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
Nothing obvious, I'm afraid. I cut-and-pasted the code directly from your email and it worked fine on my Win2K machine. 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> You might try cutting-and-pasting that code into an interpreter window to see what happens. Likewise, the following code snippet does something similar for vbs. Save it as something.vbs, and then run it from the command prompt with "cscript something.vbs" (or however you want to do it). I'd be interested to know if it gives the same error as the Python version. <code> set wmi = GetObject ("winmgmts:{impersonationLevel=impersonate}") set ServiceSet = wmi.InstancesOf ("Win32_Service") for each Service in ServiceSet WScript.Echo Service.Description Next </code> TJG 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. ________________________________________________________________________ This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ -- http://mail.python.org/mailman/listinfo/python-list