Saturday, March 10, 2012

Inno Setup, Part 6. Creating file associations during installation.

During installation you may need to create file association, i.e. make some file extension being connected with your program. In this case Windows will receive information that files with this extension should be always opened with your program. In Windows this is done with the help of registry records. Here is the code:
[Registry]
Root: HKCR; Subkey: ".ext"; ValueType: string; ValueName: ""; ValueData: "OurProgramFile"; Flags: uninsdeletevalue

Root: HKCR; Subkey: "OurProgramFile"; ValueType: string; ValueName: ""; ValueData: "Our Program File"; Flags: uninsdeletekey

Root: HKCR; Subkey: "OurProgramFile\DefaultIcon"; ValueType: string; ValueName: ""; ValueData: "{app}\OurProgram.exe,0"

Root: HKCR; Subkey: "OurProgramFile\shell\open\command"; ValueType: string; ValueName: ""; ValueData: """{app}\OurProgram.exe"" ""%1"""
In the code above we associated files with file extension .ext with OurProgram.exe which was put into {app} folder by installer. Also we set description and default icon for all the files with given file extension.
If our program is uninstalled in future, this registry records will be automatically deleted by Inno Setup.

No comments:

Post a Comment