I followed the example here, and simply copied the example by @jNizM:
Code: Select all
MsgBox % GetProcessMemory_All("chrome.exe")
My resulting complete code is:
Code: Select all
;=================================================================================================
============
; Func: GetProcessMemory_Private
; Get the number of private bytes used by a specified process. Result is in K by default, but can
also be in
; bytes or MB.
;
; Params:
; ProcName - Name of Process (e.g. Firefox.exe)
; Units - Optional Unit of Measure B | K | M. Defaults to K (Kilobytes)
;
; Returns:
; Private bytes used by the process
;-------------------------------------------------------------------------------------------------
------------
GetProcessMemory_Private(ProcName, Units="K") {
Process, Exist, %ProcName%
pid := Errorlevel
; get process handle
hProcess := DllCall( "OpenProcess", UInt, 0x10|0x400, Int, false, UInt, pid )
; get memory info
PROCESS_MEMORY_COUNTERS_EX := VarSetCapacity(memCounters, 44, 0)
DllCall( "psapi.dll\GetProcessMemoryInfo", UInt, hProcess, UInt, &memCounters, UInt,
PROCESS_MEMORY_COUNTERS_EX )
DllCall( "CloseHandle", UInt, hProcess )
SetFormat, Float, 0.0 ; round up K
PrivateBytes := NumGet(memCounters, 40, "UInt")
if (Units == "B")
return PrivateBytes
if (Units == "K")
Return PrivateBytes / 1024
if (Units == "M")
Return PrivateBytes / 1024 / 1024
}
;=================================================================================================
============
; Func: GetProcessMemory_All
; Get all Process Memory Usage Counters. Mimics what's shown in Task Manager.
;
; Params:
; ProcName - Name of Process (e.g. Firefox.exe)
;
; Returns:
; String with all values in KB as one big string. Use a Regular Expression to parse out the
value you want.
;-------------------------------------------------------------------------------------------------
------------
GetProcessMemory_All(ProcName) {
Process, Exist, %ProcName%
pid := Errorlevel
; get process handle
hProcess := DllCall( "OpenProcess", UInt, 0x10|0x400, Int, false, UInt, pid )
; get memory info
PROCESS_MEMORY_COUNTERS_EX := VarSetCapacity(memCounters, 44, 0)
DllCall( "psapi.dll\GetProcessMemoryInfo", UInt, hProcess, UInt, &memCounters, UInt,
PROCESS_MEMORY_COUNTERS_EX )
DllCall( "CloseHandle", UInt, hProcess )
list := "cb,PageFaultCount,PeakWorkingSetSize,WorkingSetSize,QuotaPeakPagedPoolUsage"
. ",QuotaPagedPoolUsage,QuotaPeakNonPagedPoolUsage,QuotaNonPagedPoolUsage"
. ",PagefileUsage,PeakPagefileUsage,PrivateUsage"
n := 0
Loop, Parse, list, `,
{
n += 4
SetFormat, Float, 0.0 ; round up K
this := A_Loopfield
this := NumGet( memCounters, (A_Index = 1 ? 0 : n-4), "UInt") / 1024
; omit cb
If A_Index != 1
info .= A_Loopfield . ": " . this . " K" . ( A_Loopfield != "" ? "`n" : "" )
}
Return "[" . pid . "] " . pname . "`n`n" . info ; for everything
}
MsgBox % GetProcessMemory_All("chrome.exe")
Note that this supposedly just works on 32-bit windows, which I have. When I run it it prints this:
picture of what it prints
So I have two issues:
1) It seems to show the memory for ONE of the processes?
2) I don't really get which line shows the memory, and of which process.
Anyway, regardless of that, what I would LIKE from the above code is for it to add up all of the memory of every process named "Chrome".
And just print the sum.
If I can have a pony I'd like a "stop" and "start" where if you click "start" it auto-updates the memory usage every n seconds. And a slider for setting how many seconds "n" is so that I can have the timer fire infrequently if I don't want the program very active and getting foreground.
But forget the pony. How can I just achieve the sum?
For example, in the screenshot pictured the sum should be approximately 3868+496+1344+1228+12512+206408+244+18756+1504+1896+1548+7432+22796+8448+1724+4324+20572+1308+12896+1148+57060+1144+85528+4436+29752+2412+1216+1384+1292+4252+34840+1520+12236 which is 567,524 KB.
I'd the program to print this. And if you want to make magic rainbow ponies, to refresh every n seconds with a slider to input n from 1 to like 200:) But no ponies, no problem.
Thanks so much!