delphi 检测进程是否存在


本文整理自网络,侵删。

 
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 字符串中加入换行符slinebreak

Delphi idsmtp发送邮件

Delphi 简单的字符串加密和解密

Delphi中动态加载image控件图片的方法

Delphi 杨辉三角

Delphi 调用dll运行正常,退出时弹出错误解决办法

Delphi禁止webbrowser弹出窗口或者脚本错误

Delphi 软件welcome窗口代码

Delphi 获取鼠标坐标

Delphi 捕捉全局异常错误的方法

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...