John Barrat
John Barrat

Reputation: 840

Associate file type/extension with a non-primary icon from an .exe file in Inno Setup

I am trying to get Inno Setup to associate three file types with my application and to assign an icon to each which have been embedded in my application.

I have edited this question now to reflect the Up-To-Date method as suggested.

I have added two icons to my main application, the Main application icon and Icon_1 and Icon_2 for file types which used by my Delphi application. I used the Resources and Images Dialog under the Project menu to add them. The script I have used for this is below.

[Registry]
; Create the application capability key
Root: HKLM; Subkey: "Software\{#MyAppPublisher}"; Flags: uninsdeletekeyifempty
Root: HKLM; Subkey: "Software\{#MyAppPublisher}\{#MyAppName}"; Flags: uninsdeletekeyifempty
Root: HKLM; Subkey: "Software\{#MyAppPublisher}\{#MyAppName}\Capability"; ValueType: string; ValueName: "ApplicationDescription"; ValueData: "Integrated Development Environment for Positron Compilers"; Flags: uninsdeletevalue
Root: HKLM; Subkey: "Software\{#MyAppPublisher}\{#MyAppName}\Capability"; ValueType: string; ValueName: "ApplicationName"; ValueData: "{#MyAppName}"; Flags: uninsdeletevalue

; List of extensions the application supports
Root: HKLM; Subkey: "Software\{#MyAppPublisher}\{#MyAppName}\Capability\FileAssociations"; ValueType: string; ValueName: ".bas"; ValueData: "{#MyAppName}.bas"; Flags: uninsdeletevalue
Root: HKLM; Subkey: "Software\{#MyAppPublisher}\{#MyAppName}\Capability\FileAssociations"; ValueType: string; ValueName: ".inc"; ValueData: "{#MyAppName}.inc"; Flags: uninsdeletevalue
Root: HKLM; Subkey: "Software\{#MyAppPublisher}\{#MyAppName}\Capability\FileAssociations"; ValueType: string; ValueName: ".psproj"; ValueData: "{#MyAppName}.psproj"; Flags: uninsdeletevalue

; Add the capability key to list of registered applications
Root: HKLM; Subkey: "Software\RegisteredApplications"; ValueType: string; ValueName: "{#MyAppName}"; ValueData: "Software\#MyAppPublisher}\{#MyAppName}\Capability"; Flags: uninsdeletevalue

; For each extension that the application supports
Root: HKCR; Subkey: "{#MyAppName}.bas"; Flags: uninsdeletekeyifempty
Root: HKCR; Subkey: "{#MyAppName}.bas"; ValueType: string; ValueName: ""; ValueData: "{#MyAppName} bas"; Flags: uninsdeletevalue
Root: HKCR; Subkey: "{#MyAppName}.bas\DefaultIcon"; Flags: uninsdeletekeyifempty
Root: HKCR; Subkey: "{#MyAppName}.bas\DefaultIcon"; ValueType: string; ValueName: ""; ValueData: "{app}\{#MyAppExeName},1"; Flags: uninsdeletevalue
Root: HKCR; Subkey: "{#MyAppName}.bas\Shell"; Flags: uninsdeletekeyifempty
Root: HKCR; Subkey: "{#MyAppName}.bas\Shell\open"; Flags: uninsdeletekeyifempty
Root: HKCR; Subkey: "{#MyAppName}.bas\Shell\open\Command"; Flags: uninsdeletekeyifempty
Root: HKCR; Subkey: "{#MyAppName}.bas\Shell\open\Command"; ValueType: string; ValueName: ""; ValueData: """{app}{#MyAppExeName}"" ""1"""; Flags: uninsdeletevalue

Root: HKCR; Subkey: "{#MyAppName}.inc"; Flags: uninsdeletekeyifempty
Root: HKCR; Subkey: "{#MyAppName}.inc"; ValueType: string; ValueName: ""; ValueData: "{#MyAppName} inc"; Flags: uninsdeletevalue
Root: HKCR; Subkey: "{#MyAppName}.inc\DefaultIcon"; Flags: uninsdeletekeyifempty
Root: HKCR; Subkey: "{#MyAppName}.inc\DefaultIcon"; ValueType: string; ValueName: ""; ValueData: "{app}\{#MyAppExeName},1"; Flags: uninsdeletevalue
Root: HKCR; Subkey: "{#MyAppName}.inc\Shell"; Flags: uninsdeletekeyifempty
Root: HKCR; Subkey: "{#MyAppName}.inc\Shell\open"; Flags: uninsdeletekeyifempty
Root: HKCR; Subkey: "{#MyAppName}.inc\Shell\open\Command"; Flags: uninsdeletekeyifempty
Root: HKCR; Subkey: "{#MyAppName}.inc\Shell\open\Command"; ValueType: string; ValueName: ""; ValueData: """{app}{#MyAppExeName}"" ""1"""; Flags: uninsdeletevalue

Root: HKCR; Subkey: "{#MyAppName}.psproj"; Flags: uninsdeletekeyifempty
Root: HKCR; Subkey: "{#MyAppName}.psproj"; ValueType: string; ValueName: ""; ValueData: "{#MyAppName} psproj"; Flags: uninsdeletevalue
Root: HKCR; Subkey: "{#MyAppName}.psproj\DefaultIcon"; Flags: uninsdeletekeyifempty
Root: HKCR; Subkey: "{#MyAppName}.psproj\DefaultIcon"; ValueType: string; ValueName: ""; ValueData: "{app}\{#MyAppExeName},1"; Flags: uninsdeletevalue
Root: HKCR; Subkey: "{#MyAppName}.psproj\Shell"; Flags: uninsdeletekeyifempty
Root: HKCR; Subkey: "{#MyAppName}.psproj\Shell\open"; Flags: uninsdeletekeyifempty
Root: HKCR; Subkey: "{#MyAppName}.psproj\Shell\open\Command"; Flags: uninsdeletekeyifempty
Root: HKCR; Subkey: "{#MyAppName}.psproj\Shell\open\Command"; ValueType: string; ValueName: ""; ValueData: """{app}{#MyAppExeName}"" ""1"""; Flags: uninsdeletevalue

Now the associations seem to have been lost. I know I have two icons in the file because when I create a short cut I can choose from either icon. What do I need to do to get the correct icon on my files?

In the registry HKEY_CLASSES_ROOT under .bas I have:

DefaultIcon - not set
ProgWithIDs - not set
PersitentHandler - {5e941d80-bf96-11cd-b579-08002b30bfeb}

Upvotes: 4

Views: 704

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202642

You have to replace the %1 with the 0-based index of the icon group within the .exe file.

Root: HKCU; Subkey: "Software\Classes\.bas\DefaultIcon"; ValueName: ""; \
  ValueType: string; ValueData: "{app}\{#MyAppExeName},ICON_GROUP_INDEX_GOES_HERE"; \
  Flags: uninsdeletevalue;

See https://learn.microsoft.com/en-us/windows/win32/shell/how-to-assign-a-custom-icon-to-a-file-type


For example, this will set .isstest icon to Inno Setup's document icon (the second icon in Compil32.exe):

[Registry]
Root: HKCU ; Subkey: "Software\Classes\.isstest"; ValueData: "Icon Test"; \
  ValueType: string; ValueName: ""; Flags: uninsdeletevalue;
Root: HKCU ; Subkey: "Software\Classes\.isstest\DefaultIcon"; ValueType: string; \
  ValueData: "C:\Program Files (x86)\Inno Setup 6\Compil32.exe,1"; ValueName: ""; \
  Flags: uninsdeletevalue;

enter image description here

enter image description here


Though this method for file association is obsolete. For an up-to-date method, see Inno Setup: Extending Windows default apps list. On the other hand, your icon problem is not related to that. In the new method, you specify the icon the same way, so you will have the same problem.

Upvotes: 2

Related Questions