unit FunFP;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Tlhelp32;
type
TForm1 = class(TForm)
ListBox1: TListBox;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
Function FindProcess(ProcessName: PChar): Boolean;
var
Snap: THandle;
Lp: Boolean;
PE: TProcessEntry32;
begin
Result := False;
snap := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if snap <= 0 then begin
Exit;
end;
PE.dwSize := SizeOf(TProcessEntry32);
Lp := Process32First(snap,PE);
while Lp do begin
if PE.szExeFile = ProcessName then begin
Result := True;
end;
Lp := Process32Next(snap,PE);
end;
CloseHandle(snap);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ListBox1.Items.Add('程序开始运行');
If FindProcess('notepad.exe') then begin
ListBox1.Items.Add('发现进程notepad.exe');
end else begin
ListBox1.Items.Add('未发现进程notepad.exe');
end;
end;
end.