我一直都在寻找各种业务功能的最简单写法,用减法的模式来开发软件。下面是的写法,如果有更简单的方法,请留言告知。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
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; |
2 条评论
沙发空缺中,还不快抢~