Jump to content

Find memory usage of process


Recommended Posts

Global Const $PROCESS_QUERY_INFORMATION = 0x400
Global Const $PROCESS_VM_READ = 0x10


MsgBox(0,"",_ProcessGetMemoryUsage("iTunes.exe"))

Func _ProcessGetMemoryUsage($sProcess)
    ;get process ID
    $nPID = ProcessExists($sProcess)
    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

[font="Verdana"]Valik:Get it straight - I'm not here to say please, I'm here to help - if my help's not appreciated then lotsa luck, gentlemen.[/font]

Link to comment
Share on other sites

  • 11 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...