Physical RAM on win32

Alex Martelli aleax at aleax.it
Fri Jan 11 09:28:16 EST 2002


"David Sparrman" <David.Sparrman at personalchemistry.com> wrote in message
news:22034d27.0201110536.37eb8f25 at posting.google.com...
> Hello,
>
>
> Is there a simple way to check the amount of physical RAM on a win32
> computer?

If you have installed WMI (Windows Management Instrumentation) there
is a way to check just about everything (via Com/Automation), although
simplicity is in the eye of the beholder.  You can get WMI from MS's
site, if you haven't installed it yet.


>>> from win32com.client import GetObject
>>> cses = GetObject("WinMgMts:").InstancesOf("Win32_ComputerSystem")
>>> for cs in cses: break

Now you have in variable cs a WMI object of Win32_ComputerSystem class,
and you can query it to your heart's contents about all of its properties.
See for example the summary at URL:
http://userpages.umbc.edu/~kbradl1/wsz/ref/WMIref.html


>>> pc.TotalPhysicalMemory
u'234278912'
>>> long(pc.TotalPhysicalMemory)/1024
228788

etc, etc.


For a general introduction to "Microsoft Windows Management Instrumentation
Scripting", see (a single URL, split by posting):
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwmi/html/
wmiscript.asp


It's a huge, omni-comprehensive, some would say over-engineered system,
but once you have installed it correctly it does make it a snap to
perform every kind of monitoring and sysadm task you can possibly
imagine (and then some).  All you need to use WMI is any COM-capable
scripting language, and Python fits the bill wonderfully well.


Alex






More information about the Python-list mailing list