WMI Help

3

3c273

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


Traceback (most recent call last):
File "<pyshell#32>", line 1, in ?
for item in c.win32_PhysicalMedia():
File "wmi.py", line 850, in __getattr__
return getattr (self._namespace, attribute)
File "C:\Python24\lib\site-packages\win32com\client\dynamic.py", line 489,
in __getattr__
raise AttributeError, "%s.%s" % (self._username_, attr)
AttributeError:
winmgmts:{impersonationLevel=impersonate,authenticationLevel=default}//./roo
t/cimv2.win32_PhysicalMedia

Any help is appreciated.
Louis
 
M

Michel Claveau

Hi!

Win32_PhysicalMedia WMI class is available only on Windows 2003 or XP

Then, swap Admin <=> Normal_user
 
M

Michel Claveau

Re!

This script run on my XP :


import win32com.client
WMIS = win32com.client.GetObject(r"winmgmts:root\cimv2")
objs = WMIS.ExecQuery("select * from Win32_PhysicalMedia")
for obj in objs:
print obj.SerialNumber
print obj.Tag
print
 
3

3c273

Michel Claveau said:
Re!

This script run on my XP :


import win32com.client
WMIS = win32com.client.GetObject(r"winmgmts:root\cimv2")
objs = WMIS.ExecQuery("select * from Win32_PhysicalMedia")
for obj in objs:
print obj.SerialNumber
print obj.Tag
print
Thank you for the input. 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??? Thanks again.
Louis
 
T

Tim Golden

3c273 said:
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
 
3

3c273

Tim Golden said:
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 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

Thanks for your input. Strangely enough, it now works whether the Win32 is
captalized or not??? I must have had a typo in there somewhere. Thanks
again.
Louis
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top