Page 1 of 1

Getting RAM usage of system processes (Windows)

Posted: Fri Mar 08, 2024 8:28 pm
by Quin
In my app, I need to get the RAM usage of some processes, including system ones. I currently have this code. It works on some processes, but a pretty frustratingly small subset, even when running as administrator. What's the proper way to do this? I found a couple code samples here, but they were all old and used functions my PB couldn't find :(

Code: Select all

Procedure GetRAMUsage(PID)
  Protected PMC.PROCESS_MEMORY_COUNTERS
  Protected Process = OpenProcess_(#PROCESS_ALL_ACCESS, #False, PID)
  If Not Process
    ProcedureReturn -1
  EndIf
  Protected Result = -1
    If GetProcessMemoryInfo(Process, @PMC, SizeOf(PROCESS_MEMORY_COUNTERS))
    Result = PMC\WorkingSetSize
  EndIf
  CloseHandle_(Process)
  ProcedureReturn Result
EndProcedure
Thanks!