DelphiFAQ Home Search:

Registering a file type on Windows 9x/2000/NT

 

commentsThis article has not been rated yet. After reading, feel free to leave comments and rate it.

This is typically the task of an installer like Wise or InstallShield, buy you may be in a situation where you have to do it manually.

Registering an application to handle a certain file type means putting a few entries in the registry. Just use the function from the code below.

program RegisterExt;

uses
  Registry;

procedure RegisterExtension(
  const sAppName: String;
  const sAppPath: String;
  const sIconName: String;
  const sExtension: String);
var
  Reg: TRegistry;
begin { RegisterExtension }
  Reg := TRegistry.Create;
  with Reg do
  begin
    RootKey := HKEY_CLASSES_ROOT;
    OpenKey('.ext', True);
    WriteString('', sAppName);
    CloseKey;
    OpenKey(sAppName, True);
    WriteString('', sAppName);
    OpenKey('DefaultIcon', True);
    WriteString('', sIconName);
    CloseKey;
    OpenKey(sAppName+'\shell\open\command', True);
    WriteString('', sAppPath);
    CloseKey;
    Free;
  end { with Reg };
end; { RegisterExtension }


begin
  RegisterExtension('MyGreatApplication',
                    'c:\program files\mystuff\myApp.exe',
                    'c:\program files\mystuff\myApp.ico',
                    '.shl');
end.
You don't like the formatting? Check out SourceCoder then!

Comments:

2006-09-21, 08:04:16
anonymous from Germany  
Cannot be correct. What happens to the parameter 'sExtension' ?

 

 

Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option.
 
It seems that you are
from Los Angeles, US .

Info/ Feedback on this

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:
photo Add a picture:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity. The owner of this web site reserves the right to delete such material.