delphi 检测进程是否存在  
官方Delphi 学习QQ群: 682628230(三千人)
频道

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;

推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.033802032470703 seconds