本文整理自网络,侵删。
获取一些系统进程要提升Debug权限,这个不用说了吧.
function GetProcessMemorySize(ProcessName: string;var Size:string;var PN:string): Boolean;
var
pProcess:THandle;
MemSize,t:Integer;
hProcSnap:THandle;
PPMCSize:Cardinal;
pe32:TProcessEntry32;
PPMC:PPROCESS_MEMORY_COUNTERS;
begin
PPMCSize := SizeOf(PROCESS_MEMORY_COUNTERS);
GetMem(PPMC, PPMCSize);
PPMC^.cb:= PPMCSize;
hProcSnap:=CreateToolHelp32SnapShot(TH32CS_SNAPALL, 0);
if hProcSnap=INVALID_HANDLE_VALUE then Exit;
pe32.dwSize:=SizeOf(ProcessEntry32);
if Process32First(hProcSnap,pe32)=True then
while Process32Next(hProcSnap,pe32)=True do
begin
if uppercase(pe32.szExeFile)=uppercase(ProcessName) then
begin
pProcess:=OpenProcess(PROCESS_ALL_ACCESS,FALSE, pe32.th32ProcessID);
if (GetProcessMemoryInfo(pProcess,PPMC,PPMCSize)) then
begin
MemSize:=PPMC^.WorkingSetSize div 1024;
t:= Length(IntToStr(MemSize))-2;
Size:=IntToStr(MemSize);
Insert(',',Size,t);
PN:=ProcessName;
FreeMem(PPMC);
Result:=True;
end
else
begin
FreeMem(PPMC);
Result:=False;
end;
end;
end;
CloseHandle(pProcess);
CloseHandle(hProcSnap);
end;
用的时候就
procedure TForm1.Button1Click(Sender: TObject);
var
str,str2:string;
begin
if (GetProcessMemorySize('QQ.exe',str,str2)) then
begin
ShowMessage('进程: '+str2+' :当前内存使用:'+ str +'K');
end;
end;
相关阅读 >>
Delphi windows 编程[19] - 改变菜单项的状态: getmenustate、enablemenuitem
delhpi如何直接获得webbrowser输入的xml文件
Delphi 使用indy idftp 通过android 上传文件
更多相关阅读请进入《Delphi》频道 >>