[delphi函数] 查找进程并显示在memo中2007-05-11 08:07 a.m.uses tlhelp32
function findprocess(afilename: string): boolean;
var
hsnapshot: thandle;//用于获得进程列表
lppe: tprocessentry32;//用于查找进程
found: boolean;//用于判断进程遍历是否完成
begin
result :=false;
hsnapshot := createtoolhelp32snapshot(th32cs_snapprocess, 0);//获得系统进程列表
lppe.dwsize := sizeof(tprocessentry32);//在调用process32first api之前,需要初始化lppe记录的大小
found := process32first(hsnapshot, lppe);//将进程列表的第一个进程信息读入ppe记录中
while found do
begin
if ((uppercase(extractfilename(lppe.szexefile))=uppercase(afilename)) or (uppercase(lppe.szexefile )=uppercase(afilename))) then
begin
result :=true;
end;
found := process32next(hsnapshot, lppe);//将进程列表的下一个进程信息读入lppe记录中
end;
end;
usage: if findprocess('rar.exe') then memo1.lines.add('rar.exe!');