procedure TForm1.Button1Click(Sender: TObject); function FindProcess(AFileName: string): Integer; var hSnapshot: THandle; lppe: TProcessEntry32; Found: Boolean; KillHandle: THandle; i:Integer; begin i:=0; 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 Inc(I); end; Found := Process32Next(hSnapshot, lppe); end; Result:=I; end; begin showmessage( intToStr( FindProcess('svchost.exe') ) ); end; --------------------------- Project1 --------------------------- 5 --------------------------- OK ---------------------------
function FindProcess(AFileName: string): Integer;
var
hSnapshot: THandle;
lppe: TProcessEntry32;
Found: Boolean;
KillHandle: THandle;
i:Integer;
begin
i:=0;
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
Inc(I);
end;
Found := Process32Next(hSnapshot, lppe);
end;
Result:=I;
end;
begin
showmessage( intToStr( FindProcess('svchost.exe') ) );
end;
---------------------------
Project1
---------------------------
5
---------------------------
OK
---------------------------