How to get Windows physical RAM using python?
Alan Kennedy
alanmk at hotmail.com
Wed Jul 30 16:59:34 EDT 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.
http://starship.python.net/crew/mhammond/
There are code samples in the following files after install
%PYTHONHOME%\Lib\site-packages\win32\lib\win32pdhutil.py
%PYTHONHOME%\Lib\site-packages\win32\lib\win32pdhquery.py
The following piece of code gives you lots of statistics about
'Memory'
#-------------------
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)
win32pdh.CollectQueryData(query)
wtfit, value = win32pdh.GetFormattedCounterValue(\
handle_on_sample, win32pdh.PDH_FMT_LONG)
print "%s%s= %d" % (stat_name, '\t'*(4-len(stat_name)//8), value)
win32pdh.CloseQuery(query)
#-------------------
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 ;-)
regards,
--
alan kennedy
-----------------------------------------------------
check http headers here: http://xhaus.com/headers
email alan: http://xhaus.com/mailto/alan
More information about the Python-list
mailing list