How to get Windows system information?

D

dpickles

Does anybody know how to get the:

Free hard disk space
Amount of CPU load
and Amount of RAM used

on windows? I am making an artificial intelligence program that has
"moods" based on how much stress the system is under, based on these
parameters. I think it could possibly be done via COM. I am not looking
for a cross-platform solution- just something that will work on
Windows. Thank you for your help!
 
M

Martin P. Hellwig

Does anybody know how to get the:

Free hard disk space
Amount of CPU load
and Amount of RAM used

on windows? I am making an artificial intelligence program that has
"moods" based on how much stress the system is under, based on these
parameters. I think it could possibly be done via COM. I am not looking
for a cross-platform solution- just something that will work on
Windows. Thank you for your help!

Have a look at WMI* , it's specifically designed to getthat kind of
stuff, there is also a python layer for WMI**.

* http://msdn.microsoft.com/library/en-us/wmisdk/wmi/wmi_reference.asp
** http://tgolden.sc.sabren.com/python/wmi.html

hth
 
P

Paul Watson

Martin said:
Have a look at WMI* , it's specifically designed to getthat kind of
stuff, there is also a python layer for WMI**.

* http://msdn.microsoft.com/library/en-us/wmisdk/wmi/wmi_reference.asp
** http://tgolden.sc.sabren.com/python/wmi.html

hth

WMI sounds like the right way to go. I recently had to whack a little
WHS because I could find no Python interface without downloading
additional modules. Do you think Tim Golden would submit it for
inclusion with the standard Python build? If so, would that require
pywin32 to be in the build or could Tim do this through ctypes?
 
D

dpickles

thank you!

from what I can see from the second website you listed, there is a way
to get harddisk space information, but is there any way to get CPU load
and RAM usage?
 
M

Martin P. Hellwig

thank you!

from what I can see from the second website you listed, there is a way
to get harddisk space information, but is there any way to get CPU load
and RAM usage?

Have a look at the snippet:

#>>> import wmi
#>>> t = wmi.WMI()
#>>> for i in t.Win32_PerfFormattedData_PerfOS_Memory():
# print(i)
#
#instance of Win32_PerfFormattedData_PerfOS_Memory
#{
# AvailableBytes = "1683038208";
# AvailableKBytes = "1643592";
# AvailableMBytes = "1605";
# CacheBytes = "89645056";
# CacheBytesPeak = "358023168";
# CacheFaultsPersec = 0;
# CommitLimit = "4131782656";
# CommittedBytes = "274153472";
# DemandZeroFaultsPersec = 91522;
# FreeSystemPageTableEntries = 150702;
# PageFaultsPersec = 91522;
# PageReadsPersec = 0;
# PagesInputPersec = 0;
# PagesOutputPersec = 0;
# PagesPersec = 0;
# PageWritesPersec = 0;
# PercentCommittedBytesInUse = 6;
# PoolNonpagedAllocs = 34580;
# PoolNonpagedBytes = "19292160";
# PoolPagedAllocs = 45037;
# PoolPagedBytes = "28307456";
# PoolPagedResidentBytes = "28053504";
# SystemCacheResidentBytes = "59023360";
# SystemCodeResidentBytes = "2568192";
# SystemCodeTotalBytes = "942080";
# SystemDriverResidentBytes = "0";
# SystemDriverTotalBytes = "6234112";
# TransitionFaultsPersec = 0;
# WriteCopiesPersec = 0;
#};
#
#>>> for i in t.Win32_PerfFormattedData_PerfOS_Processor():
# print(i)
#
#
#
#instance of Win32_PerfFormattedData_PerfOS_Processor
#{
# C1TransitionsPersec = "0";
# C2TransitionsPersec = "0";
# C3TransitionsPersec = "65";
# DPCRate = 0;
# DPCsQueuedPersec = 0;
# InterruptsPersec = 65;
# Name = "0";
# PercentC1Time = "0";
# PercentC2Time = "0";
# PercentC3Time = "95";
# PercentDPCTime = "0";
# PercentIdleTime = "100";
# PercentInterruptTime = "0";
# PercentPrivilegedTime = "0";
# PercentProcessorTime = "0";
# PercentUserTime = "0";
#};
#
#
#instance of Win32_PerfFormattedData_PerfOS_Processor
#{
# C1TransitionsPersec = "0";
# C2TransitionsPersec = "0";
# C3TransitionsPersec = "0";
# DPCRate = 0;
# DPCsQueuedPersec = 0;
# InterruptsPersec = 65;
# Name = "_Total";
# PercentC1Time = "0";
# PercentC2Time = "0";
# PercentC3Time = "0";
# PercentDPCTime = "0";
# PercentIdleTime = "0";
# PercentInterruptTime = "0";
# PercentPrivilegedTime = "0";
# PercentProcessorTime = "0";
# PercentUserTime = "0";
#};
 
T

Tim Golden

[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
 

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,774
Messages
2,569,599
Members
45,163
Latest member
Sasha15427
Top