Advertisement
jpfassis

GetPathFromPID

Sep 20th, 2019
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.46 KB | None | 0 0
  1. //uses PsAPI
  2.  
  3. function GetPathFromPID(const PID: cardinal): string;
  4. var
  5.   hProcess: THandle;
  6.   path: array[0..MAX_PATH - 1] of char;
  7. begin
  8.   hProcess := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, false, PID);
  9.   if hProcess <> 0 then
  10.     try
  11.       if GetModuleFileNameEx(hProcess, 0, path, MAX_PATH) = 0 then
  12.         RaiseLastOSError;
  13.       result := path;
  14.     finally
  15.       CloseHandle(hProcess)
  16.     end
  17.   else
  18.     RaiseLastOSError;
  19. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement