Hello,
is there any function to get the memory info from task manager?
I mean I want to know how much memory is allocated by programs.
thank you
Best Answer kon , 25 September 2014 - 07:17 PM
Hello,
is there any function to get the memory info from task manager?
I mean I want to know how much memory is allocated by programs.
thank you
Hi newbieme,
This seems like what you want:
;============================================================================================================= ; 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 }
My script runs in A_AhkVersion:=1.1.22.07, get the latest version at http://ahkscript.org/download/
Check out this AutoHotkey tutorial: http://ahkscript.git...o/AHK_Tutorial/
Read the documentation: http://ahkscript.org.../AutoHotkey.htm
No, this returns the usage of a particular program.
i want the usage of all program -> how much memory is taken.
found a way(xp):
ControlGetText, mem, Edit4, Windows Task mem:=mem/1024 MsgBox %mem%
Based on htopmini v0.8.3 by jNizM:
(this script requires a current version of AutoHotkey)
SetTimer, UpdateMemory, 1000 Fields := StrSplit("Total Physical Memory in MB,Available Physical Memory in MB,Used Physical Memory in MB" . ",Used Physical Memory in %,Total PageFile in MB,Available PageFile in MB,Used PageFile in MB,Used PageFile in %", ",") Gui, -Caption +Border +LastFound Gui, Margin, 10, 10 Gui, Font, s9 bold for i, Field in Fields { Gui, Add, Edit, x10 y+10 w80 vE%A_Index%, GuiControlGet, E%A_Index%, Pos Gui, Add, Text, % "x+10 vT" A_Index " y" (E%A_Index%Y + 5), %Field% } GuiControlGet, T2, Pos Gui, Margin, 0, 0 Gui, Add, Text, % "BackgroundTrans gGuiMove x-1 y-1 w" (T2W + 110) " H" (E8Y + 30) Gui, Show ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Excerpt from htopmini v0.8.3 ; by jNizM ; http://ahkscript.org/boards/viewtopic.php?f=6&t=254 ; https://github.com/jNizM/htopmini/blob/master/src/htopmini.ahk UpdateMemory: GMSEx := GlobalMemoryStatusEx() GuiControl, , E1, % GMSExM01 := Round(GMSEx[2] / 1024**2, 2) ; Total Physical Memory in MB GuiControl, , E2, % GMSExM02 := Round(GMSEx[3] / 1024**2, 2) ; Available Physical Memory in MB GuiControl, , E3, % GMSExM03 := Round(GMSExM01 - GMSExM02, 2) ; Used Physical Memory in MB GuiControl, , E4, % GMSExM04 := Round(GMSExM03 / GMSExM01 * 100, 2) ; Used Physical Memory in % GuiControl, , E5, % GMSExS01 := Round(GMSEx[4] / 1024**2, 2) ; Total PageFile in MB GuiControl, , E6, % GMSExS02 := Round(GMSEx[5] / 1024**2, 2) ; Available PageFile in MB GuiControl, , E7, % GMSExS03 := Round(GMSExS01 - GMSExS02, 2) ; Used PageFile in MB GuiControl, , E8, % GMSExS04 := Round(GMSExS03 / GMSExS01 * 100, 2) ; Used PageFile in % return GlobalMemoryStatusEx() { static MEMORYSTATUSEX, init := VarSetCapacity(MEMORYSTATUSEX, 64, 0) && NumPut(64, MEMORYSTATUSEX, "UInt") if (DllCall("Kernel32.dll\GlobalMemoryStatusEx", "Ptr", &MEMORYSTATUSEX)) { return { 2 : NumGet(MEMORYSTATUSEX, 8, "UInt64") , 3 : NumGet(MEMORYSTATUSEX, 16, "UInt64") , 4 : NumGet(MEMORYSTATUSEX, 24, "UInt64") , 5 : NumGet(MEMORYSTATUSEX, 32, "UInt64") } } } ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; GuiMove: PostMessage, 0xA1, 2 return Esc::ExitApp
thank you Kon , works fine
@LifeWeaver, can you add examples to the 2 functions ?
MsgBox % GetProcessMemory_All("chrome.exe")