• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 880
  • Last Modified:

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?
  • 3
1 Solution
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 "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


dhathsatoAuthor Commented:
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?
I've been searching for ages, and can't figure out what makes up the System Cache.  It seems that it is just a reserved amount of memory, and not any calculation total memory and used memory.

I will keep looking, but that's difficult to figure out!

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....



Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now