Step 4: Conditions and Properties
InstallShield 2020 » Basic MSI Tutorial
In this step, you will learn how to conditionally install data on a target system.
Operating System Conditions
A common requirement for installations is to install certain files on a system only if particular conditions are met. For example, files may be specific to an operating system or language, or should be installed only if the user has appropriate privileges.
To install a component (and its files and other data) only on particular operating systems, you can use the component’s Operating Systems property. You can modify a component’s properties by opening the Setup Design view, expanding the feature icon that contains the feature, and selecting the desired component.
To create a component that will be installed only on systems running Windows 7 or later:
|
1.
|
Open the Setup Design view. The Setup Design view is located in the Organization section of the View List. |
|
2.
|
Right-click the Help_Files feature and select New Component. |
|
3.
|
Rename the component Windows_7_Files. |
|
4.
|
Expand the Windows_7_Files component, click the Files icon for the component, and add the file ReadmeNT.txt from your tutorial files source folder by right-clicking in the Files pane and browsing to the file. |
|
5.
|
Right-click the .txt file and select Set Key File. |
|
6.
|
Click the Windows_7_Files component to display the component’s property grid. |
|
7.
|
Select the component’s Condition property and click the browse button to launch the Condition Builder dialog. |
|
9.
|
Click OK to close the Condition Builder dialog and add the condition. |
After you rebuild (by pressing F7) and run the installation (by pressing CTRL+F5), and any files or other data contained in the component will be installed only if the target system is running Windows 7 or later.
Windows Installer Conditions
The Windows Installer service stores some global information about your installation and about the user’s operating system in properties. Some properties are built into the Property table of your MSI database, and some are created and set by the Windows Installer engine when the user launches an installation.
Properties commonly used in conditions include:
|
•
|
AdminUser, which is set if the user running your installation has administrative privileges. |
|
•
|
VersionNT, numeric values describing the operating system version the user is running. |
|
•
|
PhysicalMemory, which contains the amount of RAM—in megabytes—on the user’s system. |
A Windows Installer condition is a statement of logic that compares a property value against a constant value, or tests if a property exists. For example, Windows Installer defines properties called ScreenX and ScreenY, which contain the user’s monitor resolution in pixels. A Windows Installer condition that checks that the user has at least 800 by 600 resolution would read “(ScreenX>=800) And (ScreenY>=600)”.
Conditions can also test if a property is defined. For example, the AdminUser property is set only if the user has administrative privileges, and a condition that tests if a user has administrative privileges is simply “AdminUser”.
To create a component that will be installed only if the user has administrative privileges:
|
1.
|
Right-click the Help_Files feature and select New Component. |
|
2.
|
Rename the component Admin_Component. |
|
3.
|
Expand the Admin_Component component and click the Files icon. |
|
4.
|
Add the file AdminOnly.txt from your tutorial files source folder, and set it as the key file of the component. |
|
5.
|
Click the browse button in the component’s Condition property to display the Condition Builder dialog. |
|
6.
|
In the Condition Builder dialog, type AdminUser in the Condition(s) field. |
At run time, the component’s data are installed only if the user has administrative privileges.
The next step of the tutorial describes how to modify your installation’s user interface.
See Also
Building Conditional Statements
Working with Windows Installer and Advanced UI or Suite/Advanced UI Properties