Determining the associated application

Knowing the application associated with a given file extension.


The applications associated with the file extensions are stored in the Windows Registry. To get this information first we should retrieve the "class" that a file extensions belongs to. This information can be found at:


where ".ext" is the file extension you want (like ".txt", ".bmp", etc.). Then we get the command line used to open that kind of files. To do that, we retrieve the data under


where "class" is the file class an extension belongs to. That string usually has the form


where %1 is a placeholder for the document file to open with the application, so we should find its position within the string and replace it with the filename we want to open.


The following function returns the command line of the associated application to open a documente file:

uses Registry, Windows, SysUtils;

  function GetAssociation(const DocFileName: string): string;


    FileClass: string;

    Reg: TRegistry;


    Result := '';

    Reg := TRegistry.Create(KEY_EXECUTE);

    Reg.RootKey := HKEY_CLASSES_ROOT;

    FileClass := '';

    if Reg.OpenKeyReadOnly(ExtractFileExt(DocFileName)) then


      FileClass := Reg.ReadString('');



    if FileClass <> '' then begin

      if Reg.OpenKeyReadOnly(FileClass + '\Shell\Open\Command') then


        Result := Reg.ReadString('');







Share this article!

Follow us!

Find more helpful articles: