Search code examples
inno-setupregistrykeypascalscript

Conditional registry change based on architecture


I should need your precious help with Inno Setup (be patient as I am not a programmer).

I have been asked to provide a script that performs (only in Windows 10) certain registry changes after the installation of myprogram.exe.

In all other operating system different from Windows 10 setup just runs myprogram.exe and performs no checks.

In Windows 10 after the installation of myprogram.exe I should have (in x64 versions) two registry keys being changed.

The registry keys I should change after “myprogram.exe” installation are:

In 64-bit versions:

  • HKLM\Software\Microsoft\Internet Explorer\Main\Feature Control\FEATURE_DOCUMENT_COMPATIBLE_MODE
  • HKLM\Software\Wow6432Node\Microsoft\Internet Explorer\Main\Feature Control\ FEATURE_DOCUMENT_COMPATIBLE_MODE

In 32-bit versions:

  • HKLM\Software\Microsoft\Internet Explorer\Main\Feature Control\FEATURE_DOCUMENT_COMPATIBLE_MODE

By adding a dword (in the above keys) called myprogram.exe with the hexadecimal value $7BF

I tried to add [Code] section and MinVersion: at the end of each RegWriteDwordValue statements.

I do not know how to differentiate keys to be modified from 32- and 64-bit versions and how to create the dword with the hex value $7BF.

So far this is my listing:

[Files]
Source: "C:\Meleena\myprogram.exe"; DestDir: "{tmp}"; Flags: ignoreversion

[Run]
Filename: "C:\Meleena\myprogram.exe";

[Code]

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if IsWin64 and if CurStep = sspostInstall then begin
    RegWritedwordValue(HKEY_LOCAL_MACHINE, 'Software\Microsoft\Internet Explorer\Main\Feature Control\ FEATURE_DOCUMENT_COMPATIBLE_MODE\',
      'Myprogram.exe', $7BF); Minversion:10.0.10240
    RegWritedwordValue(HKEY_LOCAL_MACHINE, 'Software\Wow6432Node\Microsoft\Internet Explorer\Main\Feature Control\ FEATURE_DOCUMENT_COMPATIBLE_MODE\',
      'Myprogram.exe', $7BF); Minversion:10.0.10240
  end;
  if IsnotWin64 and if CurStep = sspostInstall then begin
    RegWritedwordValue(HKEY_LOCAL_MACHINE, 'Software\Microsoft\Internet Explorer\Main\Feature Control\ FEATURE_DOCUMENT_COMPATIBLE_MODE\',
      'Myprogram.exe', $7BF); Minversion:10.0.10240
  end;  
end;

May you please help me out?


Solution

  • You do not need a Pascal Scripting for this. Inno Setup allows this natively. You just need to allow the setup to run in 64-bit mode.

    [Setup]
    ; Allow 64-bit mode
    ArchitecturesInstallIn64BitMode=x64
    
    [Registry]
    ; Both 32-bit and 64-bit
    Root: HKLM; \
        Subkey: "Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_DOCUMENT_COMPATIBLE_MODE"; \
        ValueType: dword; ValueName: "myprogram.exe"; ValueData: $7BF; MinVersion:10.0.10240
    
    ; On 64-bit systems, install also to Software\Wow6432Node\Microsoft\...
    ; Note the HKLM32
    Root: HKLM32; \
        Subkey: "Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_DOCUMENT_COMPATIBLE_MODE"; \
        ValueType: dword; ValueName: "myprogram.exe"; ValueData: $7BF; MinVersion:10.0.10240; \
        Check: IsWin64 
    

    Note that it's FeatureControl, not Feature Control.