Determine which Application is associated with a File Type – delphi

// Determine which application is associated with a File Type

{
  FindExecutable returns the name and handle to the executable
  (.EXE) file associated with a specified file type (.BMP)
}

function ShellFindExecutable(const FileName, DefaultDir: string): string;
var
  Res: HINST;
  Buffer: array[0..MAX_PATH] of Char;
  P: PChar;
begin
  FillChar(Buffer, SizeOf(Buffer), #0);
  if DefaultDir = '' then P := nil
  else
    P := PChar(DefaultDir);
  Res := FindExecutable(PChar(FileName), P, Buffer);
  if Res > 32 then
  begin
    P := Buffer;
    while PWord(P)^ <> 0 do
    begin
      if P^ = #0 then // FindExecutable replaces #32 with #0
        P^ := #32;
      Inc(P);
    end;
    Result := Buffer;
  end
  else
    Result := '';
end;

// Example:

procedure TForm1.Button1Click(Sender: TObject);
begin
     ShellFindExecutable('1stboot.bmp', 'c:\windows');
end;