Код:
MsgBox(0, "", _ProcessGetMemory("AutoIt3.exe") & " kb")
Func _ProcessGetMemory($nPID)
Local Const $PROCESS_QUERY_INFORMATION = 0x400
Local Const $PROCESS_VM_READ = 0x10
;get process ID
If IsString($nPID) Then $nPID = ProcessExists($nPID)
If $nPID = 0 Then Return -1
;get process handle, required for GetProcessMemoryInfo
$aRet = DllCall("Kernel32.dll", "int", "OpenProcess", "dword", _
$PROCESS_QUERY_INFORMATION+$PROCESS_VM_READ, "dword", False, "dword", $nPID)
If @error Or ($aRet[0] = 0) Then Return -1
$hProc = $aRet[0]
;create PPROCESS_MEMORY_COUNTERS to receive data, required for GetProcessMemoryInfo
$structPROCESS_MEMORY_COUNTERS = DllStructCreate("dword;dword;uint peakmemsize;uint memsize;uint;uint;uint;uint;uint;uint")
$nSize = DllStructGetSize($structPROCESS_MEMORY_COUNTERS)
;call GetProcessMemoryInfo
$aRet = DllCall("Psapi.dll", "int", "GetProcessMemoryInfo", _
"hwnd", $hProc, "ptr", DllStructGetPtr($structPROCESS_MEMORY_COUNTERS), "dword", $nSize)
;close process handle
DllCall("Kernel32.dll", "int", "CloseHandle", "hwnd", $hProc)
;return memory size in kb
Return DllStructGetData($structPROCESS_MEMORY_COUNTERS, "memsize") / 1024
EndFunc
|