How to get Windows physical RAM using python?

Alan Kennedy alanmk at
Wed Jul 30 22:59:34 CEST 2003

[Mark wrote]
> OK, How to check the amount of Windows physical RAM using python?

Well, I thought it was going to be simple, but I didn't figure
Microsoft into my considerations :-(

There's a Windows statistics module, an interface to the MS
"Performance Data Helper", as part of the Mark Hammond's Win32
Extensions, which you should install.

There are code samples in the following files after install


The following piece of code gives you lots of statistics about

import    win32pdh

items = win32pdh.EnumObjectItems(None, None,\
	 "Memory", win32pdh.PERF_DETAIL_WIZARD)[0]
for stat_name in items:
    query = win32pdh.OpenQuery()
    subquery = win32pdh.MakeCounterPath(\
    	(None,'Memory',None,None,-1,stat_name) )
    handle_on_sample = win32pdh.AddCounter(query, subquery)
    wtfit, value = win32pdh.GetFormattedCounterValue(\
    	handle_on_sample, win32pdh.PDH_FMT_LONG)
    print "%s%s= %d" % (stat_name, '\t'*(4-len(stat_name)//8), value)

But unfortunately, I can't find a 'Total Physical RAM', or comparable,
value in the output. Which I would consider a bit of an oversight by
the provider, i.e. MS.

I've looked at the other statistics available, by running this piece
of code

import win32pdh
print "options = {}\n\n"
for o in win32pdh.EnumObjects(None, None, -1):
    items, instances = win32pdh.EnumObjectItems(None, None, o, -1)
    print "options['%s'] = [" % o
    for i in items:
        print "\t'%s'," % i
    print "]\n\n"

but I can't find 'Total Physical RAM' anywhere. Am I barking up the
wrong tree? Or just barking ;-)


alan kennedy
check http headers here:
email alan:    

More information about the Python-list mailing list