判断某个进程是否存在

 

 

unit Unit1;

interface

uses
  Windows,TLHelp32, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
function FindProcess(AFileName:string):boolean;
var
hSnapshot:THandle;
lppe:TProcessEntry32;
Found:Boolean;

begin
Result:=False;
hSnapshot:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
lppe.dwSize:=SizeOf(TProcessEntry32);
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;
Found:=Process32Next(hSnapshot,lppe);
  end;
end;

 


procedure TForm1.FormCreate(Sender: TObject);
begin
  if FindProcess('Qq.exe')then
    ShowMessage('进程存在')
  else
    ShowMessage('进程不存在');

end;

end.

 

 

 

你可能感兴趣的:(Delphi)