Archive: How much memory is occupied by what or process ?


How much memory is occupied by what or process ?
How can I tell how much memory is used by a particular process ?

Is it possible to use this function GetProcessMemoryInfo ? How to do it ?


Something like this maybe:

Var /GLOBAL pid

System::Call KERNEL32::GetCurrentProcessId()i.s
Pop $pid

!include LogicLib.nsh
!define PROCESS_VM_READ 0x0010
!define PROCESS_QUERY_INFORMATION 0x0400
!define PROCESS_QUERY_LIMITED_INFORMATION 0x1000

System::Call 'KERNEL32::OpenProcess(i${PROCESS_VM_READ}|${PROCESS_QUERY_LIMITED_INFORMATION},i0,i$pid)i.r0'
${If} $0 = 0
System::Call 'KERNEL32::OpenProcess(i${PROCESS_VM_READ}|${PROCESS_QUERY_INFORMATION},i0,i$pid)i.r0'
${EndIf}
${If} $0 = 0
DetailPrint "Unable to open process $pid!"
Goto done_noprocess
${EndIf}
!define CB_PMC32 40
!define CB_PMCE32 44
System::Call '*(i,i,i,i,i,i,i,i,i,i,i0)i.r1' ; Probably only going to work for 32 bit processes
System::Call 'PSAPI::GetProcessMemoryInfo(ir0,ir1,i${CB_PMCE32})i.r2'
${If} $2 = 0
System::Call 'PSAPI::GetProcessMemoryInfo(ir0,ir1,i${CB_PMC32})i.r2'
${EndIf}
${If} $2 = 0
DetailPrint "GetProcessMemoryInfo failed"
${Else}
System::Call '*$1(i.r2,i,i,i.r3,i,i,i,i,i.r4,i,i.r5)'
${IfThen} $5 <> 0 ${|} StrCpy $4 $5 ${|} ; MSDN claims PagefileUsage is always 0 on Win7+ (Does not seem to be true but lets play it safe)
DetailPrint "cbStruct=$2 WorkingSet=$3 PrivateUsage=$4"
${EndIf}
System::Free $1
System::Call 'KERNEL32::CloseHandle(ir0)'
done_noprocess:

Anders
Thank you very much !