File association in Inno Setup

If you want to associate a program with an extension just add this instruction in your iss file :

In the section

[Setup]

ChangesAssociations = yes

^-Setup will tell Explorer to refresh its file associations information at the end of the installation, and Uninstall will do the same at the end of uninstallation.

And in the section

[Registry]

Root: HKCR; Subkey: ".mpl";                             ValueData: "{#MyAppName}";          Flags: uninsdeletevalue; ValueType: string;  ValueName: ""
Root: HKCR; Subkey: "{#MyAppName}";                     ValueData: "Program {#MyAppName}";  Flags: uninsdeletekey;   ValueType: string;  ValueName: ""
Root: HKCR; Subkey: "{#MyAppName}\DefaultIcon";             ValueData: "{app}\{#MyAppExeName},0";               ValueType: string;  ValueName: ""
Root: HKCR; Subkey: "{#MyAppName}\shell\open\command";  ValueData: """{app}\{#MyAppExeName}"" ""%1""";  ValueType: string;  ValueName: ""

Explanations

Root: HKCR; Subkey: ".magi"; ValueData: "MyMAGIApplication"; ValueType: string; ValueName: ""; Flags: uninsdeletevalue. This instruction add “.magi” key in the registry, with more accurate in HKEY_CLASSES_ROOT (HKCR). In this instruction we also have ValueName="" so it get the default value in the registry.

add extension in registry

Root: HKCR; Subkey: "MyMAGIApplication"; ValueData: "Program MAGI"; ValueType: string; ValueName: ""; Flags: uninsdeletekey In order to add the key MyMAGIApplication in HKCR with the value “Program MAGI”.

Root: HKCR; Subkey: "MyMAGIApplication\DefaultIcon"; ValueData: "{app}\MAGI.EXE,0"; ValueType: string; ValueName: "" In order to associate an icon contains in the executable. “0” indicates that it’s the first icon present in the executable MAGI.EXE.

Root: HKCR; Subkey: "MyMAGIApplication\shell\open\command"; ValueData: """{app}\MAGI.EXE"" ""%1"""; ValueType: string; ValueName: "" In order to add the subkey shell\open\command. With this instruction, Windows is able to launch application MAGI.EXE when an user click on a file with extension “.magi”.

And the result in registry :

Add entry in KHCR\MyMAGIApplication

Leave a Comment