vb script to monitor process memory usage

Discussion in 'Scripting' started by Dee, Oct 6, 2009.

  1. Dee

    Dee Guest

    Hi

    I want to monitor a particular process for private bytes which I can see is
    the amount of memory it is using, however I cannot find the object to use.

    I have the below, but it does not give the object i want

    any ideas?, thanks

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

    Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process")

    For Each objProcess in colProcessList
    Wscript.Echo "Process: " & objProcess.Name
    Wscript.Echo "Process ID: " & objProcess.ProcessID
    Wscript.Echo "Thread Count: " & objProcess.ThreadCount
    Wscript.Echo "Page File Size: " & objProcess.PageFileUsage
    Wscript.Echo "Page Faults: " & objProcess.PageFaults
    Wscript.Echo "Working Set Size: " & objProcess.WorkingSetSize
    Next
     
    Dee, Oct 6, 2009
    #1
    1. Advertisements

  2. Hard to say unless you tell us in what way your code fails to deliver.
     
    Pegasus [MVP], Oct 6, 2009
    #2
    1. Advertisements

  3. Dee

    Dee Guest

    No to worry I managed to sort it out with the below

    ' Get raw and cooked data performance counter instances for the
    'wscript process running this script
    on error resume next
    dim strComputer, objWMIService, RawProc, processname, threshold

    processname = "'xxx'"

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    set RawProc = GetObject("winmgmts:" _
    & "Win32_PerfRawdata_Perfproc_process." _
    & "name='xxx'")

    Wscript.Echo "opcwbemi process raw PageFaultsPerSec = " _
    & RawProc.PrivateBytes
    threshold = RawProc.PrivateBytes

    if RawProc.PrivateBytes > "50000000" then
    wscript.echo "threshold breached"
    end if

    set objWMIService = nothing
    set RawProc = nothing
     
    Dee, Oct 6, 2009
    #3
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.