WMI Help

Tim Golden mail at timgolden.me.uk
Thu Jul 13 15:39:54 EDT 2006


3c273 wrote:
> Hello,
> When I run the following at an interactive interpreter on Windows XP, I get
> the expected results. But if I save it to a file and run it, it generates
> the following error. (And it generates the same error either way on Windows
> 2000)
> 
> import wmi
> c=wmi.WMI()
> for item in c.win32_PhysicalMedia():
>     print item

A couple of things:

+ As someone else has pointed out, Win32_PhysicalMedia
appears to be new to XP/2k3. (This happens quite a lot
with WMI classes; you need to check the small-print).
So that explains why it won't work on  your Win2K box
nor on mine.

+ In addition, the bit after the "c." (here, Win32_PhysicalMedia)
is case-sensitive. So you have to put c.Win32_PhysicalMedia
(notice the capital "W"). I'm not actually sure why this should
be, and when I get a moment I'll take a look at the code to
see, but it's true nonetheless.

Under the covers, the module is doing exactly what
Michel showed you in his second post (WMIS = GetObject etc.)

 > Strange that this does not return the serial number
 > reported by other hardware utilities (SIW for one) and on both of my
 > machines this number ends with 202020202020202020202020???

Strange indeed. Unfortunately, what you see is what you get
with WMI. I don't have access to an XP machine to test, but
let me know if this code doesn't work:

<code>
import wmi
c = wmi.WMI ()
for item in c.Win32_PhysicalMedia ():
   print item

</code>

Good luck with WMI

TJG



More information about the Python-list mailing list