Using Windows Installer Properties to Dynamically Modify Text Files

InstallShield 2020

Project:This information applies to the following project types:

Basic MSI
DIM
InstallScript MSI
Merge Module
MSI Database
Transform

This information does not apply to InstallScript projects; however, the InstallScript language includes string functions for finding and modifying string variables and literals. You can use these functions in InstallScript projects.

You can use a Windows Installer property to specify text strings for which you are searching or modifying. You can also use a property to specify the text files that you are including or excluding in your search.

At run time, Windows Installer uses MsiFormatRecord to resolve the property value, and it uses that value to modify your text file. This enables you to use data that end users enter in dialogs, or other configuration information that is determined at run time, when your product’s text files are modified at run time.

Example

The following procedure demonstrates how to let end users specify during installation an IP address that must be written to an XML-based web.config file at run time. The web.config file is installed with the product to INSTALLDIR, and it contains XML such as the following:

<?xml version="1.0" encoding="UTF-8"?>

<configuration>

    <appSettings>

        <add key="IP Address" value="default" />

    </appSettings>

</configuration>

The default value in bold must be replaced by the IP address that an end user enters.

Note that you can substitute a hard-coded value with a property for the following change set settings in the Text File Changes view:

Include Files
Exclude Files

In addition, you can use a property for the following change item settings in the Text File Changes view:

Find What
Replace With
Insert Text

The property that you specify in any of these settings must be enclosed within square brackets, and the property name must be all uppercase; for example, [MYPROPERTY].

Step 4 of the procedure is slightly different, depending on the project type, since Windows Installer controls the user interface of Basic MSI installations, and the InstallScript engine controls the user interface of InstallScript MSI installations.

To let end users specify the IP address:

1. In the View List under System Configuration, click Text File Changes.
2. Add and configure a change set item, which identifies the file for which you want the installation to search:
a. Right-click the Text File Changes explorer and then click Add Change Set.

InstallShield adds a new change set item. Steps 2b through 2d explain how to configure its settings, which are displayed in the right pane.

b. In the Target Folder setting, select the [INSTALLDIR] directory property.
c. In the Include Files setting, enter the following:

web.config

d. Leave the default values for the other settings.
3. Add and configure a change item, which identifies the search-and-replace criteria:
a. In the Text File Changes explorer, right-click the change set item that you created in step 2, and then click Add Change.

InstallShield adds a new change item. Steps 3b through 3e explain how to configure its settings, which are displayed in the right pane.

b. In the Action setting, select Replace.
c. In the Find What setting, enter the following:

<add key="IP Address" value="default"

d. In the Replace With setting, enter the following:

<add key="IP Address" value="[MYPROPERTY]"

e. Leave the default values for the other settings.
4. Use the property in a dialog. This part of the procedure depends on which project type you are using.
For Basic MSI projects:
a. In the View List under User Interface, click Dialogs.
b. In the Dialogs explorer, expand the All Dialogs folder, and click the language under the dialog that should contain the User Name control. As an alternative, you can add a new dialog.
c. Add an Edit Field control to the dialog, and set its Property property to the following:

MYPROPERTY

For InstallScript MSI projects:
a. In the View List under Behavior and Logic, click InstallScript.
b. Find the dialog code in the OnFirstUIBefore event for the dialog that should contain the User Name control, and add a call to the Windows Installer API function MsiSetProperty. For example, if you want end users to enter the IP address in an edit box on the SdShowDlgEdit1 dialog that you have added to your project, you would add an MsiSetProperty call as shown in the following lines of code:

Dlg_SdShowDlgEdit1:

    nResult = SdShowDlgEdit1 (szTitle, szMsg, szField1, svEdit1);

    MsiSetProperty (ISMSI_HANDLE, "MYPROPERTY", svEdit1);

    if (nResult = BACK) goto Dlg_SdWelcome;

5. Build your release.

Tip:If you are creating a multilanguage project and you want to use a property that can have different values based on the language that your installation uses, you can use a localizable property. For more information, see Creating a Localizable Property.

See Also