您的位置:首页 > 其它

判断某个进程是否存在

2010-02-05 23:58 260 查看
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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: