请教,如何获得某程序占用多少内存
如题,如果想获得当前进程中某程序占有多少内存,应该用什么方法 MemGetStats() 补充,例如我的进程中有一个 xx.exe 的进程,我想获取这个进程所占用的内存大小是多少 例如我的进程中有一个 xx.exe 的进程,我想获取这个进程所占用的内存大小是多少 $objWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2")$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Process", "WQL", 0X10+0X20)
If IsObj($colItems) Then
For $objItem In $colItems
$Name = $objItem.Name;进程名
$Priority = $objItem.Priority;优先权
$ProcessId = $objItem.ProcessId;pid
$ParentProcessId = $objItem.ParentProcessId;父进程pid
$PeakWorkingSetSize = $objItem.PeakWorkingSetSize;内存
$ThreadCount = $objItem.ThreadCount;线程数
$CommandLine = $objItem.CommandLine;进程参数
$ExecutablePath = $objItem.ExecutablePath;路径
MsgBox(0, 0, "进程名:" & $Name & @CRLF & "使用内存:"& $PeakWorkingSetSize / 1024 & " K")
Next
Else
MsgBox(0, "错误", "无法创建WMI项目")
EndIf 正在学API,来个API的,高手纠正下。#Include <WinAPI.au3>
#Include <array.au3>
$PROCESS_QUERY_INFORMATION=0x400
$PROCESS_QUERY_LIMITED_INFORMATION=0x1000
$PROCESS_SET_INFORMATION =0x0200
$PROCESS_SET_QUOTA =0x0100
$PROCESS_SUSPEND_RESUME =0x0800
$PROCESS_TERMINATE =0x0001
$PROCESS_VM_OPERATION =0x0008
$PROCESS_VM_READ =0x10
$PROCESS_VM_WRITE =0x0020;常量
$_PIDN="explorer.exe"
$_PID=ProcessExists($_PIDN)
$_Return=DllCall("Kernel32.dll","hwnd","OpenProcess","dword",0x400+0x10,"int",False,"dword",$_PID)
If Not IsArray($_Return) Or $_Return=0 Then
MsgBox(0,"error","API错误代码:" & _WinAPI_GetLastError())
Exit
EndIf
$_Struct=DllStructCreate("DWORD;DWORD;DWORD;DWORD;DWORD;DWORD;DWORD;DWORD;DWORD;DWORD")
$_Return=DllCall("Psapi.dll","int","GetProcessMemoryInfo","hwnd",$_Return,"ptr",DllStructGetPtr($_Struct),"dword",DllStructGetSize($_Struct))
MsgBox(0,"","进程:"&$_PIDN & " 占用内存: " & DllStructGetData($_Struct,4)/1024 & " KB") 本帖最后由 bing614 于 2009-9-4 15:54 编辑
用到的API原型;~ C++
;~ BOOL WINAPI GetProcessMemoryInfo(
;~ __in HANDLE Process,
;~ __outPPROCESS_MEMORY_COUNTERS ppsmemCounters,
;~ __in DWORD cb
;~ );
;~ Psapi.dll
;~ http://msdn.microsoft.com/en-us/library/ms683219(VS.85).aspx
;~ C++
;~ typedef struct _PROCESS_MEMORY_COUNTERS {
;~ DWORDcb; 本结构大小
;~ DWORDPageFaultCount; 中断次数
;~ SIZE_T PeakWorkingSetSize;使用内存高峰
;~ SIZE_T WorkingSetSize; 当前使用的内存
;~ SIZE_T QuotaPeakPagedPoolUsage;使用页面缓存池高峰
;~ SIZE_T QuotaPagedPoolUsage;使用页面缓存池
;~ SIZE_T QuotaPeakNonPagedPoolUsage;使用非分页缓存池高峰
;~ SIZE_T QuotaNonPagedPoolUsage;使用非分页缓存池
;~ SIZE_T PagefileUsage;使用分页文件
;~ SIZE_T PeakPagefileUsage;使用分页文件的高峰
;~ }PROCESS_MEMORY_COUNTERS, *PPROCESS_MEMORY_COUNTERS;
;~ DWORD;DWORD;DWORD;DWORD;DWORD;DWORD;DWORD;DWORD;DWORD;DWORD
;~ C++
;~ HANDLE WINAPI OpenProcess(
;~ __inDWORD dwDesiredAccess,
;~ __inBOOL bInheritHandle,
;~ __inDWORD dwProcessId
;~ );
;~ Kernel32.dll
;~ http://msdn.microsoft.com/en-us/library/ms684320(VS.85).aspx $nc=ProcessGetStats("360se.exe",0)
MsgBox(0,"",$nc) ;得到内存占用(单位/字节B) 知道这用吗???? #Include <WinAPIEx.au3>
_WinAPI_GetProcessMemoryInfo
页:
[1]