How to get Windows system information?

Tim Golden tjgolden at gmail.com
Sun Jan 15 04:39:27 EST 2006


[posting through Google; not sure how it will format]

re info on WMI website: please note that the examples I
give no the WMI pages are *nowhere near* exhausting
what WMI can do. They don't even scratch the surface.
And I all too rarely add to them.

If you look around the net, you'll find absolutely loads
of recipes for doing things with WMI. And it's usually
easy to translate them into Python. So, for example,
Googling for WMI CPU load takes you straight to
this page:

http://www.robvanderwoude.com/wshexamples_0o.html

which (after some fairly intrusive boilerplate stuff)
ends up selecting from Win32_Processor. So, in
Python:

<code>
import wmi
c = wmi.WMI ()
for i in c.Win32_Processor ():
  print i

# gives, among other things, a LoadPercentage
# field.
</code>

Now, what the different fields mean sometimes requires
a bit more research. But the Microsoft WMI pages
sometimes hit the spot, and indeed, a search for
WMI LoadPercentage

brings up this page:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwmi/html/mngwmi.asp

with a useful snippet on using WMI events to monitor
CPU Load.

And so on. By and large, whatever you can think of doing
with WMI, someone's done before. And if someone's done
it in VBS (or Perl, or whatever), we can do it in Python.

HTH
Tim




More information about the Python-list mailing list