Link to home
Start Free TrialLog in
Avatar of dhathsato
dhathsatoFlag for United States of America

asked on

Returning values with WMI

I need to return: Total System Cache, commit charge values and kernel memory values from a Win2003 machine.  Currently I have been returning Total and available physical memory via WMI.  Does anyone know what class to use to get the values mentioned above?
Avatar of RobSampson
RobSampson
Flag of Australia image

Hi, have a look at the properties of the Win32_PerfFormattedData_PerfOS_Memory class.  Run this code in file called MemoryDetails.vbs, with the command
cscript MemoryDetails.vbs

and you will see the output.  See if that's what you need.

I got this code from Microsoft's ScriptoMatic v2, which allows to choose all of the published Win32 classes, and you should look through those to get what you need.

'===================
On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

arrComputers = Array("D09790RING")
For Each strComputer In arrComputers
   WScript.Echo
   WScript.Echo "=========================================="
   WScript.Echo "Computer: " & strComputer
   WScript.Echo "=========================================="

   Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
   Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfOS_Memory", "WQL", _
                                          wbemFlagReturnImmediately + wbemFlagForwardOnly)

   For Each objItem In colItems
      WScript.Echo "AvailableBytes: " & objItem.AvailableBytes
      WScript.Echo "AvailableKBytes: " & objItem.AvailableKBytes
      WScript.Echo "AvailableMBytes: " & objItem.AvailableMBytes
      WScript.Echo "CacheBytes: " & objItem.CacheBytes
      WScript.Echo "CacheBytesPeak: " & objItem.CacheBytesPeak
      WScript.Echo "CacheFaultsPersec: " & objItem.CacheFaultsPersec
      WScript.Echo "Caption: " & objItem.Caption
      WScript.Echo "CommitLimit: " & objItem.CommitLimit
      WScript.Echo "CommittedBytes: " & objItem.CommittedBytes
      WScript.Echo "DemandZeroFaultsPersec: " & objItem.DemandZeroFaultsPersec
      WScript.Echo "Description: " & objItem.Description
      WScript.Echo "FreeSystemPageTableEntries: " & objItem.FreeSystemPageTableEntries
      WScript.Echo "Frequency_Object: " & objItem.Frequency_Object
      WScript.Echo "Frequency_PerfTime: " & objItem.Frequency_PerfTime
      WScript.Echo "Frequency_Sys100NS: " & objItem.Frequency_Sys100NS
      WScript.Echo "Name: " & objItem.Name
      WScript.Echo "PageFaultsPersec: " & objItem.PageFaultsPersec
      WScript.Echo "PageReadsPersec: " & objItem.PageReadsPersec
      WScript.Echo "PagesInputPersec: " & objItem.PagesInputPersec
      WScript.Echo "PagesOutputPersec: " & objItem.PagesOutputPersec
      WScript.Echo "PagesPersec: " & objItem.PagesPersec
      WScript.Echo "PageWritesPersec: " & objItem.PageWritesPersec
      WScript.Echo "PercentCommittedBytesInUse: " & objItem.PercentCommittedBytesInUse
      WScript.Echo "PoolNonpagedAllocs: " & objItem.PoolNonpagedAllocs
      WScript.Echo "PoolNonpagedBytes: " & objItem.PoolNonpagedBytes
      WScript.Echo "PoolPagedAllocs: " & objItem.PoolPagedAllocs
      WScript.Echo "PoolPagedBytes: " & objItem.PoolPagedBytes
      WScript.Echo "PoolPagedResidentBytes: " & objItem.PoolPagedResidentBytes
      WScript.Echo "SystemCacheResidentBytes: " & objItem.SystemCacheResidentBytes
      WScript.Echo "SystemCodeResidentBytes: " & objItem.SystemCodeResidentBytes
      WScript.Echo "SystemCodeTotalBytes: " & objItem.SystemCodeTotalBytes
      WScript.Echo "SystemDriverResidentBytes: " & objItem.SystemDriverResidentBytes
      WScript.Echo "SystemDriverTotalBytes: " & objItem.SystemDriverTotalBytes
      WScript.Echo "Timestamp_Object: " & objItem.Timestamp_Object
      WScript.Echo "Timestamp_PerfTime: " & objItem.Timestamp_PerfTime
      WScript.Echo "Timestamp_Sys100NS: " & objItem.Timestamp_Sys100NS
      WScript.Echo "TransitionFaultsPersec: " & objItem.TransitionFaultsPersec
      WScript.Echo "WriteCopiesPersec: " & objItem.WriteCopiesPersec
      WScript.Echo
   Next
Next
'================

Regards,

Rob.
Avatar of dhathsato

ASKER

Thank you for your response, it is very helpful.  I still don't see how I can get the value of the System Cache, do I need to do calculations to get this?
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I was thinking that maybe the CacheBytes value above would be the actual "current" usage, whereas the one shown in Task Manager might be a long term calculation of averages or amount reserved.
Perhaps you should try to collect the CacheBytes value for a while and see if gets close to the Task Manager reported value, over time....

Regards,

Rob.