Register your own file extensions in the Windows registry (Views: 102)


I have an application that create files. I want those files to be associated to my application so that when you double click on those files will launch my application and open the particular file. How do I do this?


Take a look at the registry (HKEY_CLASSES_ROOT) to see what exactly is possible. Basically, you have to add an entry that equals the file extension, one that equals an unique name and the action. And you have to tell Windows that you have registered a new extension. Something like:

{ ... }
  Regist: TRegistry;
    Regist := TRegistry.Create;
    Regist.RootKey := HKEY_CLASSES_ROOT;
    {file type}
    if Regist.OpenKey('.xyz' {= your extension}, True) then
      Regist.WriteString('', 'xyz-file' {= unique name});
    if Regist.OpenKey('xyz-file' {= same unique name}, True) then
      Regist.WriteString('', 'xyz super file'
        {= short description, is shown in explorer});
    if Regist.OpenKey('xyz-file\DefaultIcon', True) then
      {third icon of your exe, 0 is the main icon I think, of course you can use
                        other files than Application.ExeName}
      Regist.WriteString('', Application.ExeName + ', 3');
    if Regist.OpenKey('xyz-file\Shell\Open\Command', True) then
      Regist.WriteString('', Application.ExeName + ' "%1"');
        {or other/ additional parameters}
      Result := True;
    {you can add more for edit, print etc.}
    {tell Windows we have done it}

<< Back to main page