Conditions in Wise Package Studio - A Way to Make Application Installation More Robust
This article is a step by step guide to Set Conditions for features, components, environment variables and the value of properties using Wise Package Studio (WPS).
Introduction
One way to make your Windows Installer installations more robust is to add conditions. Conditions define criteria that the operating system, end user, or installation must meet for the installation to continue.
Conditions are expressions that can be either evaluated to true or false. By associating a condition with an element such as a property, feature or component within your MSI, you can determine whether something happens or not during the installation of that MSI. Through evaluating a condition to either true or false the MSI can allow or disallow an installation to continue, display certain dialogs depending on user input, install or not install certain features or components, executes or does not executes certain actions.
Based on whether the condition is true or not, you can determine whether to:
- Allow the installation to continue.
- Install certain features and components.
- Display certain dialogs or dialog controls.
- Execute custom actions you add in MSI Script.
As part of the Wise Package Studio tool, conditions can be created as appropriate. However, conditions are integral to most complex installations and in order to carry out advanced customization of your installation MSI they will almost certainly need to be used.
Conditions can be created in five main areas within Wise Package Studio:
- The Feature Page
- Launch conditions
- Conditions for Controls on Dialogs
- Conditions attached to Components
- Conditions for Custom Action
Following section will explain step by step guide to set conditions in different areas within Wise Package Studio.
Feature page
You can add conditions on the Features page on the Installation Expert. The condition will then appear in the features drop down list. For example you could add system changes to a feature and these changes will only be installed if the feature is installed. You could then set a condition under the feature so that these changes are only installed if the feature is installed and the condition evaluates to true.
Adding a Condition to a Feature
Start Wise Package Studio then open Windows Installer Editor.
On the feature page in the Installation Expert - click on the name of the feature to which you want to add a condition. You will see in the example below that "Feature1" is selected.
Click on the Add Condition command button situated on the right of the dialog.
The Feature Condition dialog box appears.
Click on the Build command button
Create condition using the Condition Builder
Enter a condition for your installation. For this example, enter VersionNT>=600.
Click Ok once finished
Click Ok
You will see the condition for the feature as shown below.
Adding Launch Conditions To Create Dynamic Installations
Launch conditions are expressions that must evaluate to true for the installation to start. The launch condition is the first action which takes place in the execute sequence. Launch conditions are very flexible, easy to create, and give you the ability to create conditions to meet the needs of the most complex installations.
For example, suppose you need a customized launch condition that specifies only the version of the operating system. Open your installation, and then go to the dialog or section that enables you to specify conditions. This location varies by the application you are using. Next, create variables for the conditions you want. If you are more comfortable working with tables, enter variables for the condition in the LaunchCondition table. The procedure below is an example of how to create a launch condition using Windows Installer Editor in Wise Package Studio.
Creating a Launch Conditions:
Start Wise Package Studio then open Windows Installer Editor.
Click the Setup Editor tab, then click the Product tab.
Right-click on Launch Conditions.
In the menu, Select New > Launch Condition.
The Launch Condition Details dialog appears.
Click on the Build command button and create you condition using the Condition Builder
Create condition using the Condition Builder
Enter a condition for your installation. For this example, enter
ScreenX >= 800 AND ScreenY >= 600
This condition ensures that the installation will only continue if the target computer has a screen resolution of 800 x 600
Click on Check Syntax to verify your condition is correct
Click Ok once finished
Fill in the fields as follows:
- Condition: (Which is already built ScreenX >= 800 AND ScreenY >= 600)
- Message Text: Enter text to explain the condition. For this example, enter
This application requires screen resolution of 800 x 600
You will see the condition on the right side pan of setup editor as shown in below:
You can specify additional criteria to narrow a launch condition. Below are some variables you can apply to modify an operating system.
To set other requirements, such as criteria for a user domain environment variable, enter a condition where the user domain equals your criteria. For example:
%USERDOMAIN = "XYZ"
Use case will ensure that condition is case sensitive
To define a variable in either all upper- or lowercase characters, use a tilde(~) in the condition. For example:
%USERDOMAIN = ~ "XYZ"
Or Check Ignore case box which will take care of all upper- or lowercase characters
You will see the condition on the right side pan of setup editor as shown in below
Combining two or more Conditions
To combine the condition add Boolean operators. The following example displays it, the order of the variables is not important since the entire statement must be satisfied for the condition to be true.
- %USERDOMAIN = "XYZ" AND ScreenX >= 800 AND ScreenY >= 600
When you set variables for a condition, it is important to add text in case the application does not start successfully. If the conditions you entered in your installation validate, the application starts up successfully when the user launches it. If there are validation problems, the application does not start up and the user does not know why. Fill in the Message Text field in the Launch Condition Details dialog or a related field in the application with user instructions to identify the problem for the user. For example, if the variables for a condition are ScreenX >= 800 AND ScreenY >= 600 AND %USERDOMAIN = "XYZ" then you might add the following message text: This application requires screen resolution of 800 x 600 and that you are logged in to the XYZ domain.
Launch conditions give you the opportunity to enhance your installation by creating custom criteria. When you add a condition to your installation, be sure to test it thoroughly. A comprehensive understanding of Windows Installer launch conditions can add robustness to your installation and improve the user's installation experience.
Component Conditions
Component conditions can be set anywhere in the installation and install resources based on conditions you have defined. They are important to the repackaging process because they control which files and keys install on an operating system or target machine in a particular domain.
You must use component conditions if the installation supplies .DLL files for specific operating systems. It is recommended that you use component conditions if the installation contains other files exclusive to specific operating systems. Adding these files gives the installation the ability to install the correct files based on the operating system and then continue with the installation. This prevents the installation from breaking if it detects an operating system for which it doesn't have compatible files.
It is simple to add logic that installs a file based on a condition. You add rows to the Component table that contain the files and conditions necessary in the installation. For instance, suppose you are unsure which operating system is on the computer that will run your installation. In the Component table, you can create .DLL components for the individual operating systems and then enter conditions that install the appropriate .DLL. The table below lists example conditions for the various operating systems.
After adding the appropriate files and conditions, the Component table in your installation should look similar to the following graphic.
Editing Component Conditions
Once a component condition is defined, you might need to modify it. To edit component conditions, use an editor that is capable of displaying component details. The following example uses the Component Details dialog available in Windows Installer Editor in Wise Package Studio.
To edit a condition:
In Wise Package Studio, start Windows Installer Editor by double-clicking its icon.
In Windows Installer Editor, click the Setup Editor tab, then click the Components tab.
Expand the component tree if needed to view all of the components in your installation.
Right-click on the component and select Details.
The Component Details dialog appears.
Edit the condition in the Condition field.
If you prefer to edit conditions in the Condition Builder, click the Build button. Any changes you make in the Condition Builder automatically display in the Condition field once you click OK in the Condition Builder.
Click OK.
Component conditions can make your installation run seamlessly from start to finish. To add this functionality to your installations, include component conditions that install any files specific to the Windows operating systems on which your installation might run. This lets you create a single customized installation per operating system without creating multiple installations.
Conditions for Actions/Custom Actions
You can also set conditions on actions by selecting MSI Script tab. The MSI Script tab contains a number of standard Wise for Windows Installer actions whose conditions should not be altered. However, you may find the need to set a condition for any custom actions you may have created as part of the installation.
Below is an example(just for demonstration)of a custom action that will Execute VBScript.
Start Wise Package Studio then open Windows Installer Editor.
Click the MSI Script tab. Select Execute Differed tab
In MSI Script click on Execute Program From Installation
Fill in the details
Now I want to run this Custom Action only for the first time when I install the application.
Now Navigate To Installation Mode Select All Custom Actions
Double click on the Custom Action Name just created.
Following Window will appear.
Select Location Tab
Ensure that the position of the new custom action is just above InstallFinalize.
Enter Condition as NOT Installed or take the help of condition builder to build the condition
"Not Installed" is simply giving the instruction that if the action is not already installed on the system to install it.
Click Ok to Finish.
Now you can see the custom action within condition
If NOT Installed then Run the Action(Custom action for which you have added the condition) End
Briefly, about Condition Builder
Use the Condition Builder dialog to build conditions that test the installed state of components and features and the value of properties and environment variables. You can access the Condition Builder dialog from different areas of Windows Installer Editor.
Perhaps the easiest way to create a condition is through the use of the Condition Builder. The Condition Builder helps remove some of the common mistakes that are made when creating conditions by providing you with a list of existing Features, Components, Environment Variables and Properties to choose from. The selection of operator buttons that are available to you when building a condition in Wise for Windows Installer are also provided along with the tilde button (~), parentheses button and quotation button ( " ). When you have built your condition you can check that the syntax of that conditional statement is correct by clicking on the Check Syntax button. This will bring any errors to your attention through the use of an error box.
This diagram is taken from help file to explain about Condition Builder.
Operator Buttons
Most of the operator buttons in the middle of the dialog, starting with the = button, are described in Conditional Statement Syntax . They include logical, comparative, string, and bitwise operators.
- Use the ~ button before an operator to make the condition case-insensitive.
- Use the () buttons to enclose parts of the condition, which changes the order of precedence.
- Use the " button to enclose literal text.
Lists
Fields
Select the kind of item the condition checks. You can check the installed state for features and components, and you can check the value of properties and environment variables.
Values
If you selected Environment Variable or Property in the Fields list, double-click the name of an environment variable or a property to insert it into a condition.
State
Use this list only to check the installed state of a component or feature. Action refers to what occurs during installation, and Installed refers to the current state of the destination computer.
Install/Action state
Use this list only to check the installed state of a component or feature. Absent means the feature or component is not installed, Advertised means it is advertised, Local means it is installed on the local hard drive, and Source means it is installed to run from the installation source.
Value Types Inside a Condition
You can use different types of values inside a condition:
- Feature
- Components
- Properties
- Environment Variables
Using Properties in a condition
Property values in Wise for Windows Installer are case sensitive by default. However, you can make them case insensitive by placing a tilde (~) before the operator. You can either check whether a property is true or not or check whether a property evaluates to a certain value.
If you wish to check that a property evaluates to a certain value you should use the Condition Builder.
In the Condition Builder dialog box select the Property folder from the list of objects in the Fields list. The Values list will display the list of properties that are available to you as part of the installation.
From the Values list double click on the property you require. This property will now appear in the Condition list box.
Select the equals sign (=) from the selection of operators in the middle of the dialog. An equals sign will therefore be inserted in the Condition list box.
Click on the Condition list box after the equals sign and enter the value you wish to check your property against.
Click the OK button on the Condition Builder dialog box.
Using Environment Variables in condition
Environment Variables are not case sensitive but must be preceded with a percent symbol (%). To build a condition that checks an environment table you will again make use of the Condition Builder. The same steps are taken to create this condition as were taken when building the condition to check a property. However, on this occasion you will select the Environment Variable folder from the list of objects in the Fields list and the Values list will display the list of Environment Variables that are available to you on the destination computer.
Condition-Checks if a Feature/Component is currently installed
A condition cannot only check if a feature or component is currently installed but you can also create a condition to see how a feature or component is installed. A feature may be installed to run advertised, locally or from source all of which are options you can set when installing a feature or component.
In the Condition Builder dialog box select the feature folder from the list of objects available in the Fields list. The features being installed by the MSI will appear in the Values list. In the example below, there are 3 features - Client, Common and Server.
Single click on the Feature you wish to check. You will see in the example below we have clicked on the Client feature.
In the State list double click on Installed.
Click the equals (=) command button.
In the Install/Action state list, double-click one of the following to check the action state of the feature or condition:
- Absent: Will not be installed by this installation.
- Advertised : Will be installed in an advertised state.
- Local : Will be installed locally by this installation.
- Source : Will be installed to run from installation source by this installation.
When you have completed the condition, it should look something like our example below.
Click OK in the Condition Builder Box
Building Condition that checks if a Feature/Component will be installed
In the Condition Builder dialog box select the feature folder from the list of objects available in the Fields list. The features being installed by the MSI will appear in the Values list. Again in the example below there are 4 features - feature, feature1 feature2 and feature3.
Start Wise Package Studio then open Windows Installer Editor
On the feature page in the Installation Expert - click on the name of the feature to which you want to add a condition. You will see in the example below that "Feature1" is selected.
Click on the Add Condition command button situated on the right of the dialog.
The Feature Condition dialog box appears.
Click on the Build command button
Create you condition using the Condition Builder
Single click on the Feature you wish to check. You will see in the example below we have clicked on the feature1
.
In the State list double click on Action.
Click the equals (=) command button.
In the Install/Action state list, double-click one of the following to check the action state of the feature or condition:
- Absent: Will not be installed by this installation.
- Advertised : Will be installed in an advertised state.
- Local : Will be installed locally by this installation.
- Source : Will be installed to run from installation source by this installation.
Click OK to close the Condition Builder Box.
When you have completed the condition, it should look something like our example below.
Click OK to close.
When you have completed the condition, it should look something like our example below.
Summary of Conditional Statement Syntax
This section describes the syntax of conditional statements which is available in help file.
Conditional Expressions
This table and the following list summarize the syntax to use in conditional expressions.
- Symbol names and values are case sensitive.
- Environment variable names are not case sensitive.
- Literal text must be enclosed between quotation marks ("text").
- Note: Literal text containing quotation marks cannot be used in conditional statements because there is no escape character for quotation marks inside literal text. To do a comparison against literal text containing quotation marks, the literal text should be put in a property. For example, to verify that the SERVERNAME property does not contain any quotation marks, define a property called QUOTES in the Property table with a value of " and change the condition to NOT SERVERNAME QUOTES.
- Nonexistent property values are treated as empty strings.
- Floating point numeric values are not supported.
- Operators and precedence are the same as in the BASIC and SQL languages.
- Arithmetic operators are not supported.
- Parentheses can be used to override operator precedence.
- Operators are not case sensitive.
- For string comparisons, a tilde "~" prefixed to the operator performs a comparison that is not case sensitive.
- Comparison of an integer with a string or property value that cannot be converted to an integer is always
Access Prefixes
The following table shows the prefixes to use to access various system and installer information for use in conditional expressions.
Logical Operators
The following table shows the logical operators in conditional expressions, in order of high-to-low precedence.
Comparative Operators
The following table shows the comparison operators used in conditional expressions. These comparison operators can only occur between two values.
Substring Operators
The following table shows the substring operators used in conditional expressions. Substring operators can occur between two string values.
Bitwise Numeric Operators
The following table shows the bitwise numeric operators in conditional expressions. These operators can occur between two integer values
Feature and Component State Values
The following table shows where it is valid to use the feature and component operator symbols.
The following table shows the feature and component state values used in conditional expressions. These states are not set until MsiSetInstallLevel is called, either directly or by the CostFinalize action.
For example, the conditional expression "&Feature=3" evaluates to True only if MyFeature is changing from its current state to the state of being installed on the local computer, INSTALLSTATE_LOCAL.
















































Comments
Nice Post
Nice Post
Wiseuser
Altiris Certified Professional
Very helpful article
Very helpful article
where we can get step by step instruction to create MSI usingWSI
Hi I am new in wsi,
i created msi using install sheild or msi from .net but wsi look new for me,
i just started 3 days ago, i can create new msi using wsi (wise for window installer0 using installation expert , but still want to learn differnt type action,
except installation expert we do have other active forum where i can get details,
i want to learn some action, like if i choose only me while installation should get error.
thanks and Regards
Would you like to reply?
Login or Register to post your comment.