appo icon

Search process

appo | PRO | 12/27/13 10:03:11 PM UTC | 0 ⭐ | 605 👁️ | Never ⏰ | []
Delphi |

630 B

|

None

|

0 👍

/

0 👎

function FindProcess(const ExeFile: string): string;
const TH32CS_SNAPPROCESS = $00000002;
var SH: THandle;
TP: TProcessEntry32;
PID: DWORD;
I: Integer;
S: string;
begin Result := '';
if ExeFile = '' then Exit;
SH := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if Integer(SH) < 0 then Exit;
TP.dwSize := SizeOf(TProcessEntry32);
if not Process32First(SH, TP) then Exit;
PID := 0;
for I := 0 to 999 do
begin
S := UpperCase(TP.szExeFile);
if SameText(ExeFile, S) then
begin
PID := TP.th32ProcessID;
Break;
end;
if not Process32Next(SH, TP) then Break;
end;
if PID = 0 then Exit;
Result := S;
end;
 
// Coded by Appo //

Comments