Mega Code Archive

 
Categories / Delphi / Examples
 

Get FullPath Application of Any Object

Title: Get FullPath Application of Any Object Question: You want get app fullpath of any Object? This procedure can help you. Answer: Uses psAPI; procedure GetAppName(hWindow: THandle; var Buffer: String); { hWindow = Handle of the Object that you want know the path. Buffer = variable that receive the fullpath. } var dPID: dWord; hHandle: THandle; begin GetWindowThreadProcessId(hWindow, @dPID); // Get PID of Object. SetLength(Buffer, MAX_PATH); // Set Length of Buffer. hHandle := OpenProcess( // Get Handle of Process. PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, true, dPID ); if GetModuleFileNameEx( // Check and get App FullPath Name. hHandle, 0, PChar(Buffer), MAX_PATH ) 0 then SetLength(Buffer, StrLen(PChar(Buffer))); // If not reset Length of Buffer. end;