How to get memory usage of a process with WMI

Posted by Cereal Wednesday, October 14, 2009 5:10:35 AM Categories: _Tous les articles WMI
Rate this Content 0 Votes

After few hours of search i have found a easy solution and the right option to get memory size used by a process.



On Error Resume Next
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
Dim sComputerName, sProcessName
sComputerName = "."
sProcessName = "explorer.exe"

Set objWMIService = GetObject("winmgmts:\\" & sComputerName & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name ='" & sProcessName & "'", "WQL",wbemFlagReturnImmediately + wbemFlagForwardOnly)

For Each objItem In colItems
    WScript.Echo "-- Process --"
    WScript.Echo "Caption : " & objItem.Caption
    WScript.Echo "Name : " & objItem.Name
    WScript.Echo "Mem usage : " & " - " & objItem.WorkingSetSize / 1024
Next 


Simple-Tech.info
Comments are closed on this post.
Site Map | Printable View | © 2008 - 2012 Simple-Tech.info | Powered by mojoPortal | HTML 5 | CSS | Design by mitchinson