SHARE
TWEET

GetPathFromPID

jpfassis Sep 20th, 2019 (edited) 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top