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 计算ip地址范围

Delphi 隐藏进程代码

Delphi fdquery1查询,有无返回集

Delphi 生成xml 方法 与 Delphi txt文件操作

Delphi xe5 Delphi 解析 json

Delphi动态建立panel无法更改颜色?

Delphi md5加密字符串

Delphi 一个拼图工具的制作思路

Delphi中编写参数个数可变的函数

Delphi 获取文件夹下包括子目录所有文件

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



打赏

取消

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

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

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

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

评论

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