Has anyone gotten WMI to work on Win2000? GetObject("WinMgmts.........

David Bolen db3l at fitlinxx.com
Fri Sep 28 01:47:16 CEST 2001


bwharvey at hotmail.com (BWH) writes:

> I've seen several messages on the group of people trying to get things
> working, but I constantly get Attribute Err.
> 
> from win32com.client import GetObject
> 
> processes = GetObject("WinMgmts://127.0.0.1/root/cimv2").\
> InstancesOf("Win32_process")
> 
> for process in processes:
>     print process.Name

Try:

    for process in processes:
        print process.Properties_('Name')

You can also use _Methods('xxx') to find a particular method.

There was some past discussion on this, and I think the issue is that
if you've run makepy on the object, than only those properties and
methods actually defined in the object library may be used as a direct
attribute of the object, since those are the only ones defined in the
Python wrapper objects.  This is actually where a dynamic binding
would be nicer since it just tries to pass everything through, but
without the makepy you'd probably have some data type problems.

But you can use the Properties_ and Methods_ calls to identify a
property or method using the appropriate enumeration objects at
runtime, and it's not that much extra coding.

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list