本文整理自网络,侵删。
function CheckProcessExist(const AFileName: string): Boolean;var //用于获得进程列表 hSnapshot: THandle; //用于查找进程 lppe: TProcessEntry32; //用于判断进程遍历是否完成 Found: Boolean;begin Result := False; //获得系统进程列表 hSnapshot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); //在调用Process32FirstAPI之前,需要初始化lppe记录的大小 lppe.dwSize := SizeOf(TProcessEntry32); //将进程列表的第一个进程信息读入ppe记录中 Found := Process32First(hSnapshot, lppe); while Found do begin if ((UpperCase(ExtractFileName(lppe.szExeFile)) = UpperCase(AFileName)) or (UpperCase(lppe.szExeFile) = UpperCase(AFileName))) then begin Result := True; end; //将进程列表的下一个进程信息读入lppe记录中 Found := Process32Next(hSnapshot, lppe); end;end;
procedure TForm4.btn1Click(Sender: TObject);begin if CheckProcessExist(Trim(edt1.Text)+'.exe') then begin ShowMessage('检测到了'); end else begin ShowMessage('不存在'); end;end;
相关阅读 >>
更多相关阅读请进入《Delphi》频道 >>