How to get process memory usage?

Viewed 75

I have been searching for how to get processes memory usage, is this possible using only an AutoHotkey script?

If someone could point where to start, thanks.

1 Answers

How about this function?

GetProcessMemoryInfo(PID) {
    size := 440
    VarSetCapacity(pmcex,size,0)
    ret := ""
    
    hProcess := DllCall( "OpenProcess", UInt,0x400|0x0010,Int,0,Ptr,PID, Ptr )
    if (hProcess)
    {
        if (DllCall("psapi.dll\GetProcessMemoryInfo", Ptr, hProcess, Ptr, &pmcex, UInt,size))
            ret := NumGet(pmcex, (A_PtrSize=8 ? "16" : "12"), "UInt")/1024 . " K"
        DllCall("CloseHandle", Ptr, hProcess)
    }
    return % ret
}

Taken from AHK_Task Manager: https://www.autohotkey.com/board/topic/79151-ahk-task-manager/

Related