How do I customize Windows Installer Properties using WiseScript ?
Customizing installations by editing the Windows Installer tables is potentially dangerous and may not provide all the functionality necessary for your desired customizations. Directly editing the tables, when done incorrectly, could corrupt your installation. One way you can bypass these limitations is calling custom .dll files from within Windows Installer and passing multiple parameters to and from each .dll. However, this can be a tedious process. Fortunately, WiseScript provides scripting capability for your installation development and lets you easily retrieve and set Windows Installer properties, and evaluate WiseScript expressions to customize your installation.
This article explains the actions available from the WiseScript tool and provides an example that demonstrates the ability to pass information back and forth between Windows Installer and WiseScript during the installation.
Get Windows Installer Property
This action reads the value of a Windows Installer property set during installation and places it into a variable. On the Get Windows Installer dialog, you provide the name of the Windows Installer property value to retrieve and specify which WiseScript variable will hold the value. The Get Windows Installer Property script action initializes the WiseScript variable, so you do not need to initialize the variable with a Set Variable script action.
Set Windows Installer Property
This action sets a Windows Installer property to a defined value. On the Set Windows Installer dialog, enter a property name from the .MSI or .WSI. Then, enter a value to assign to the property. If you want to assign the value of a WiseScript variable to the property, use %VARIABLE%.
Evaluate Windows Installer Condition
This action evaluates a Windows Installer condition and places the value of the condition into a defined variable. This variable is set to 1 if true, or 2 if false. Use the Evaluate Windows Installer Condition action to perform an action based on a Windows Installer condition defined in the .msi. To use this action, utilize the same syntax of the condition's logic from the .msi and a variable.
Utilizing the power of WiseScript actions
This example demonstrates the ability to pass information back and forth between Windows Installer and WiseScript during the installation. You can use this particular example for parsing a directory path passed from a Windows Installer property and placing it into the registry.
To create a new Windows Installer package:
- Open Wise for Windows Installer, Wise Installation Express, or Windows Installer Editor in Wise Package Studio or Wise Installation Studio.
- Select New from the File menu. The New Installation File dialog appears.
- In the New Installation File dialog, select Windows application and the Create .WSI or .WSM project file that can be compiled into an .MSI or .MSM option.
- Open the Files page in Installation Expert.
- In the lower-left pane, select the Program Files folder and click the New Folder button. The Create New Folder dialog appears.
- In the New Folder Name field, type a name for the new folder, such as MyApplication.
- Add a file named Installation Test to the newly created folder.
To locate the Windows Installer property for the directory:
- In Setup Editor, click the Tables tab.
- Select the Directory table.
- In the DefaultDir column, locate the Installation Test folder that you created on the Files page. In this row, make sure INSTALLDIR appears in the Directory column.
To create the Custom Action that calls the WiseScript:
- Click the MSI Script tab, then select the Execute Immediate tab in the Installation Sequence pane.
- In the Installation Sequence pane, select the line to add the Custom Action. For this example, select the line after CostFinalize. Directory resolution occurs during the CostFinalize action.
- In the Actions pane, double-click Run WiseScript from installation. The Run WiseScript from Installation dialog appears.
- In the Run WiseScript from Installation dialog, type a name that defines the routine of your Custom Action in the Custom Action Name field. For this example, type ParseDirectory.
- Click the Options button and select Create New WiseScript. The Save As dialog appears.
- In the Save As dialog, browse to the location where you would like to save your WiseScript, then click Save. If you are using Wise for Windows Installer or Wise for Visual Studio .NET, WiseScript Express opens. If you are using Wise Package Studio, WiseScript Editor opens.
To copy the Windows Installer property into a WiseScript variable:
- In the WiseScript tool, double-click Get Windows Installer Property in the Actions list. The Get Windows Installer Property dialog appears.
- In the Get Windows Installer Property dialog, enter the following:
Type the variable name that will hold the value. For this example, type DIRECTORY.
Type INSTALLDIR. This is the name of the property to retrieve.
- Click OK.
To parse the directory using the variable:
- In the Installation Script pane, select the line after the Get Windows Installer Property action.
- In the Actions list, double-click the Parse String action. The Parse String dialog appears.
- In the Parse String dialog, enter the following information:
Type \. This is the substring character where the parse will occur.
Destination Variable 1:
Type DIRECTORY. This replaces the original DIRECTORY variable with the characters from the beginning of the string to the backslash.
Destination Variable 2:
Type EXTRA. This places any characters right of the backslash in this variable.
Operation. Select Split value at last occurrence of pattern from the drop-down list.
This removes the last backslash of the variable DIRECTORY.
- To add a second Parse String action, complete steps 2–3 again, but type new variable names in the Destination Variable 1 and Destination Variable 2 fields.
The first time through the steps, the Parse String action removes the trailing backslash, and the second time through, it removes the directory name. Although Windows Installer always adds a backslash at the end of a directory, it is not necessary to keep a trailing backslash in the WiseScript variable.
To set the Windows Installer property back to the .MSI:
- In the Installation Script pane, select the last Parse String action.
- In the Actions list, double-click Set Property. The Set Property dialog appears.
- In the Set Property dialog, enter the following information:
Type %DIRECTORY%. This new value goes to the property.
- Click OK.
- Click the Compile button.
- Close the WiseScript tool.
- In MSI Script, click OK in the Run WiseScript from Installation dialog.
To write a registry key based on the new property:
- In Installation Expert, click the Registry page link.
- In the bottom-left pane, select the location where you want to create the new registry key.
- Click the Add button and select Key. The Registry Details dialog appears.
- In the Registry Details dialog, enter the following information:
Select Create/Update key and value.
Enter the name of the key you want to create.
Enter the name of the key under which you want to create the directory.
Type [INSTALLDIRNEW]. This is the property you set in the WiseScript.
Leave the default of String. This places the directory into the registry.
- Click OK.
After completing the above steps, click Compile and run your script on a test computer. By following the above procedures, you can retrieve Windows Installer properties from the .msi, manipulate the data with a WiseScript, and send the information back to the .msi during installation. The example detailed above is useful when you need to trim backslashes from directories during the installation. You can also use this example as a springboard for ideas to customize and add power to your installation without directly editing the Windows Installer tables.