Search code examples
inno-setuppascalscript

Inno Setup and Two conditions in Check


I'm writting a simple Inno Setup Script for my application. I did all the stuff I wanted but I'm blocking on something.

My app has two mode, Computer and Client that the user chooses at the start of the installation. If Client mode is picked, the application must start with windows. Also my app can be installed on both Windows version (32 and 64Bits), so not the same path for the registry key.

To make it start with windows, I added this at the end of my Inno setup script :

[Registry]
Check: IsWin64; Root: HKCU; Subkey: "Software\Microsoft\Windows\CurrentVersion\Run"; ValueType: string; Permissions: users-full; ValueName: "MyApp"; ValueData: "{app}\AutoexecX86.cmd";

Check: Not IsWin64; Root: HKCU; Subkey: "Software\Microsoft\Windows\CurrentVersion\Run"; ValueType: string; Permissions: users-full; ValueName: "MyApp"; ValueData: "{app}\Autoexec.cmd";

How can I add the condition that my app start only with the condition "Client mode is choosen". (ClientRadioButton.Checked)


Solution

  • Check parameter documentation says:

    Besides a single name, you may also use boolean expressions. See Components and Tasks parameters for examples of boolean expressions.

    Components and Tasks parameters documentation says:

    Besides space separated lists, you may also use boolean expressions as Components and Tasks parameters. Supported operators include not, and, and or. ...


    So, add an auxiliary function like IsClientMode:

    function IsClientMode: Boolean;
    begin
      Result := ClientRadioButton.Checked;
    end;
    

    And combine it with your existing IsWin64 condition using and boolean operator:

    [Registry]
    Check: IsWin64 and IsClientMode; ...
    Check: (not IsWin64) and IsClientMode; ...
    

    Alternatively, particularly if the expression gets too complicated or when it is used frequently, you can factor it out to a separate function:

    function IsClientModeOnWin64: Boolean;
    begin
      Result := IsWin64 and IsClientMode;
    end;