Returning values with WMI

Posted on 2007-07-23
Last Modified: 2008-01-09
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?
Question by:dhathsato
    LVL 65

    Expert Comment

    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



    Author Comment

    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?
    LVL 65

    Accepted Solution

    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!

    LVL 65

    Expert Comment

    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

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
    Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
    Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
    In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now