For the specified file, we get the path to the application associated with it.
1 2 3 4 5 6 7 8 9 10 11 |
Uses Winapi.ShellAPI; ... var filePath, assocExePath: WideString; begin filePath:= 'C:\Windows\Fonts\tahoma.ttf'; assocExePath:= ShellFindExecutable(filePath); ShowMessage(assocExePath); end; |
Options
filePath - path to the file
Result
The path to the associated application, or an empty string if unsuccessful.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
function ShellFindExecutable(filePath: string): string; var Res: HINST; Buffer: array[0..MAX_PATH] of Char; P: PChar; begin FillChar(Buffer, SizeOf(Buffer), #0); P := nil; Res := FindExecutable(PChar(filePath), P, Buffer); if Res > 32 then begin P := Buffer; while PWord(P)^ <> 0 do begin if P^ = #0 then P^ := ' '; Inc(P); end; Result := Buffer; end else Result := ''; end; |