[python-win32] Why Win32_ prefixed classed in wmi didn't work?

Tim Golden mail at timgolden.me.uk
Thu Jan 24 10:09:25 CET 2008


thunder thunder54007 wrote:
> Hello, here is the problem.
> code like this in pythonwin:
> 
>>>> import wmi
>>>> c = wmi.WMI()
>>>> print c.Win32_NetWorkAdapter.AdapterTypeID
> None
>>>> print c.Win32_NetWorkAdapter.Availability
> None
>>>> print c.Win32_NetWorkAdapter.Caption
> None
>>>> print c.Win32_NetWorkAdapter.AdapterType
> None <python-win32 at python.org>
> 
> this same thing happed for class Win32_Keyboard, it seems that there is not
> value for these attributes, even the "Caption" attribute. why?

(I've probably misled you with some of the examples
exchanged in private email), Although the properties
& methods are visible via the WMI class, they won't
have any values until you pick a particular instance
of that class.

For *which* of your network adapters do you expect
to see values above? All of the WMI classes return
lists of their instances -- even when, as in the case
of Win32_OperatingSystem, there's obviously only one.

You need to do something like this:

<code>
import wmi
c = wmi.WMI ()

for nic in c.Win32_NetworkAdapter ():
   print nic.Caption
   print nic.AdapterTypeId
   print nic.Availability
   # or just
   # print nic

</code>

If you want a specific device, you'll have to pass in
some kind of identifying qualifier to the Win32_NetworkAdapter
call, eg:

<code>
import wmi
c = wmi.WMI ()

for nic in c.Win32_NetworkAdapter (
   Description="Cisco Systems VPN Adapter"
):
   print nic

</code>

TJG


More information about the python-win32 mailing list