Andrew Truckle
Andrew Truckle

Reputation: 19197

Inno Setup - Register for both 32 bit and 64 bit

This issue has only raised itself now that I am registering my file types:

; Register File Types 32 bit
Root: HKCR; SubKey: ".mwb"; ValueType: string; ValueData: "MeetingScheduleAssistant.MeetingWorkBook"; Flags: uninsdeletekey
Root: HKCR; SubKey: "MeetingScheduleAssistant.MeetingWorkBook"; ValueType: string; ValueData: "Meeting Workbook"; Flags: uninsdeletekey
Root: HKCR; SubKey: "MeetingScheduleAssistant.MeetingWorkBook\Shell\Open\Command"; ValueType: string; ValueData: """{app}\MeetSchedAssist.exe"" ""%1"""; Flags: uninsdeletekey
Root: HKCR; Subkey: "MeetingScheduleAssistant.MeetingWorkBook\DefaultIcon"; ValueType: string; ValueData: "{app}\MeetSchedAssist.exe,0"; Flags: uninsdeletevalue

Root: HKCR; SubKey: ".srr"; ValueType: string; ValueData: "MeetingScheduleAssistant.SoundRotaReport"; Flags: uninsdeletekey
Root: HKCR; SubKey: "MeetingScheduleAssistant.SoundRotaReport"; ValueType: string; ValueData: "Sound Rota Report"; Flags: uninsdeletekey
Root: HKCR; SubKey: "MeetingScheduleAssistant.SoundRotaReport\Shell\Open\Command"; ValueType: string; ValueData: """{app}\MeetSchedAssist.exe"" ""%1"""; Flags: uninsdeletekey
Root: HKCR; Subkey: "MeetingScheduleAssistant.SoundRotaReport\DefaultIcon"; ValueType: string; ValueData: "{app},1"; Flags: uninsdeletevalue

My installer ships with the above 32bit exe but it also has a _64x executable. What is the right way to register from both environments? Do I just duplicate the code, like this:

; Register File Types 32 bit
Root: HKCR; SubKey: ".mwb"; ValueType: string; ValueData: "MeetingScheduleAssistant.MeetingWorkBook32"; Flags: uninsdeletekey
Root: HKCR; SubKey: "MeetingScheduleAssistant.MeetingWorkBook32"; ValueType: string; ValueData: "Meeting Workbook"; Flags: uninsdeletekey
Root: HKCR; SubKey: "MeetingScheduleAssistant.MeetingWorkBook32\Shell\Open\Command"; ValueType: string; ValueData: """{app}\MeetSchedAssist.exe"" ""%1"""; Flags: uninsdeletekey
Root: HKCR; Subkey: "MeetingScheduleAssistant.MeetingWorkBook32\DefaultIcon"; ValueType: string; ValueData: "{app}\MeetSchedAssist.exe,0"; Flags: uninsdeletevalue

Root: HKCR; SubKey: ".srr"; ValueType: string; ValueData: "MeetingScheduleAssistant.SoundRotaReport32"; Flags: uninsdeletekey
Root: HKCR; SubKey: "MeetingScheduleAssistant.SoundRotaReport32"; ValueType: string; ValueData: "Sound Rota Report"; Flags: uninsdeletekey
Root: HKCR; SubKey: "MeetingScheduleAssistant.SoundRotaReport32\Shell\Open\Command"; ValueType: string; ValueData: """{app}\MeetSchedAssist.exe"" ""%1"""; Flags: uninsdeletekey
Root: HKCR; Subkey: "MeetingScheduleAssistant.SoundRotaReport32\DefaultIcon"; ValueType: string; ValueData: "{app},0"; Flags: uninsdeletevalue

; Register File Types 64 bit
Root: HKCR; SubKey: ".mwb"; ValueType: string; ValueData: "MeetingScheduleAssistant.MeetingWorkBook64"; Flags: uninsdeletekey
Root: HKCR; SubKey: "MeetingScheduleAssistant.MeetingWorkBook64"; ValueType: string; ValueData: "Meeting Workbook"; Flags: uninsdeletekey
Root: HKCR; SubKey: "MeetingScheduleAssistant.MeetingWorkBook64\Shell\Open\Command"; ValueType: string; ValueData: """{app}\MeetSchedAssist_x64.exe"" ""%1"""; Flags: uninsdeletekey
Root: HKCR; Subkey: "MeetingScheduleAssistant.MeetingWorkBook64\DefaultIcon"; ValueType: string; ValueData: "{app}\MeetSchedAssist_x64.exe,0"; Flags: uninsdeletevalue

Root: HKCR; SubKey: ".srr"; ValueType: string; ValueData: "MeetingScheduleAssistant.SoundRotaReport64"; Flags: uninsdeletekey
Root: HKCR; SubKey: "MeetingScheduleAssistant.SoundRotaReport64"; ValueType: string; ValueData: "Sound Rota Report"; Flags: uninsdeletekey
Root: HKCR; SubKey: "MeetingScheduleAssistant.SoundRotaReport64\Shell\Open\Command"; ValueType: string; ValueData: """{app}\MeetSchedAssist_x64.exe"" ""%1"""; Flags: uninsdeletekey
Root: HKCR; Subkey: "MeetingScheduleAssistant.SoundRotaReport64\DefaultIcon"; ValueType: string; ValueData: "{app}\MeetSchedAssist_x64.exe,0"; Flags: uninsdeletevalue

I can't see how this would work because the user double-clicks the file so how does it know which of the exe files to use?

Upvotes: 1

Views: 352

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202534

If you use the modern method for registering associations, you can register multiple applications (so both 32-bit and 64-bit versions of your application). System will then prompt user to select which application to use, the first time user tries to open the respective file type. Also, the user will be able to change the decision in the Control Panel (or Windows 10 Settings app).

See Inno Setup: Extending Windows default apps list

You will have to repeat the whole registration for both versions (with unique IDs both for the software and the associations). You can use preprocessor to avoid having to repeat the code.

This needs Windows Vista at least.


If you want to stick with your way to register the application (or if you need to support older versions of Windows), you will need to register one version of your application only. Either according to the bitness of the system or according to user preference.

You can use a scripted constant in the [Registry] section:

[Registry]
...
Root: HKCR; SubKey: "MeetingScheduleAssistant.MeetingWorkBook32\Shell\Open\Command"; \
    ValueType: string; ValueData: """{app}\{code:GetExecutableToRegister}"" ""%1"""; \
    Flags: uninsdeletekey
...

To select the executable according to the bitness of the system, use IsWin64 function:

[Code]
function GetExecutableToRegister(Param: string): string;
begin
  if IsWin64 then
    Result := 'MeetSchedAssist_x64.exe'
  else
    Result := 'MeetSchedAssist.exe';
end;

To select the executable according to user preference, you can use [Tasks] and WizardIsTaskSelected function:

[Tasks]
Name: register32; Description: "Register 32-bit executable"; Check: IsWin64; \
    flags: unchecked;
Name: register64; Description: "Register 64-bit executable"; Check: IsWin64 
[Code]
function GetExecutableToRegister(Param: string): string;
begin
  if IsWin64 and WizardIsTaskSelected('register64') then
    Result := 'MeetSchedAssist_x64.exe'
  else
    Result := 'MeetSchedAssist.exe';
end;

(untested)


Update by OP:
This code I managed to get to work:

; Register File Types
Root: HKCR; SubKey: ".mwb"; ValueType: string; ValueData: "MeetSchedAssist.MWB"; Flags: uninsdeletekey
Root: HKCR; SubKey: ".srr"; ValueType: string; ValueData: "MeetSchedAssist.SRR"; Flags: uninsdeletekey
Root: HKCR; Subkey: "MeetSchedAssist.MWB"; ValueType: string; ValueData: "Meeting Workbook Schedule"; Flags: uninsdeletekey
Root: HKCR; Subkey: "MeetSchedAssist.SRR"; ValueType: string; ValueData: "Sound Rota Report"; Flags: uninsdeletekey
Root: HKCR; SubKey: "MeetSchedAssist.MWB\Shell\Open\Command"; ValueType: string; ValueData: """{app}\{code:GetExecutableToRegister}"" ""%1"""; Flags: uninsdeletekey
Root: HKCR; SubKey: "MeetSchedAssist.SRR\Shell\Open\Command"; ValueType: string; ValueData: """{app}\{code:GetExecutableToRegister}"" ""%1"""; Flags: uninsdeletekey

The above uses the Tasks. Although I have a separate issue about the tasks, and, for some reason the "Desktop" did not refresh. But the above works. Using the new system fails.

Upvotes: 2

Related Questions