Advertisement
appo

Search process

Dec 27th, 2013
438
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.63 KB | None | 0 0
  1. function FindProcess(const ExeFile: string): string;
  2. const TH32CS_SNAPPROCESS = $00000002;
  3. var SH: THandle;
  4. TP: TProcessEntry32;
  5. PID: DWORD;
  6. I: Integer;
  7. S: string;
  8. begin Result := '';
  9. if ExeFile = '' then Exit;
  10. SH := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  11. if Integer(SH) < 0 then Exit;
  12. TP.dwSize := SizeOf(TProcessEntry32);
  13. if not Process32First(SH, TP) then Exit;
  14. PID := 0;
  15. for I := 0 to 999 do
  16. begin
  17. S := UpperCase(TP.szExeFile);
  18. if SameText(ExeFile, S) then
  19. begin
  20. PID := TP.th32ProcessID;
  21. Break;
  22. end;
  23. if not Process32Next(SH, TP) then Break;
  24. end;
  25. if PID = 0 then Exit;
  26. Result := S;
  27. end;
  28.  
  29. // Coded by Appo //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement