• Javascript
  • Python
  • Go
Tags: inno-setup

Adding Conditional Statements in [Run] Section of Inno Setup

Inno Setup is a popular tool used for creating installation packages for Windows applications. It provides a user-friendly interface and pow...

Inno Setup is a popular tool used for creating installation packages for Windows applications. It provides a user-friendly interface and powerful scripting capabilities to customize the installation process. One of the most useful features of Inno Setup is its support for conditional statements, which allow you to control the installation process based on certain conditions. In this article, we will explore how to add conditional statements in the [Run] section of Inno Setup.

The [Run] section is used to specify the files and commands that should be executed during the installation process. This section is typically used to perform tasks such as installing dependencies, registering DLLs, and creating desktop shortcuts. By adding conditional statements in this section, you can control which tasks are performed based on the user's system configuration or other conditions.

To add a conditional statement in the [Run] section, you need to use the "Flags" parameter. This parameter allows you to specify a condition that must be met for the specified file or command to be executed. The condition can be a simple expression or a complex Boolean expression using logical operators like AND, OR, and NOT. Let's take a look at some examples to understand this better.

Example 1:

[Run]

Filename: "setup.exe"; Flags: not Is64BitInstallMode; Description: "Install 32-bit version"; Components: main

In this example, we have used the "not Is64BitInstallMode" condition. This means that the specified file will only be executed if the user's system is not running on a 64-bit operating system. This can be useful if your application has both 32-bit and 64-bit versions and you want to install the appropriate version based on the user's system configuration.

Example 2:

[Run]

Filename: "msiexec.exe"; Parameters: "/i myapp.msi /qn"; Flags: shellexec; Description: "Install MyApp"; Components: main

In this example, we have used the "shellexec" flag. This flag tells Inno Setup to execute the specified file using the Windows shell instead of launching it directly. This can be useful if you want to run an MSI file with specific parameters during the installation process.

Example 3:

[Run]

Filename: "myapp.exe"; Flags: runhidden; Description: "Start MyApp"; Components: main

In this example, we have used the "runhidden" flag. This flag tells Inno Setup to launch the specified file in a hidden window. This can be useful if you want to run a command or executable without displaying any user interface.

Apart from these flags, there are several other flags that you can use in the [Run] section to add conditional statements. Some of the commonly used ones are "postinstall", "dontcloseonexit", and "skipifsilent". You can refer to the Inno Setup documentation for a complete list of available flags.

In addition to using flags, you can also use the "Check" parameter to specify a function or procedure that will be executed to determine if the file or command should be run. This gives you more flexibility in defining conditions and allows you to perform custom checks based on your application's requirements.

Example 4:

[Run]

Filename: "setup.exe"; Flags: runasoriginaluser; Description: "Install MyApp"; Check: IsNotAdmin; Components: main

In this example, we have used the "runasoriginaluser" flag, which

Related Articles