How can I write values from a property into a text file within the MSI?
Microsoft's Windows Installer architecture does not support writing to a text file, so this sample uses a Run WiseScript from Installation custom action. This script takes you through the steps of accepting end user input on a dialog in an .msi installation, and then creates a text file and writes the information out to a text file that it creates on the destination computer. The User Information dialog contains two edit field controls used to accept the USERNAME and COMPANYNAME properties from the end user. This sample uses the USERNAME and COMPANYNAME properties.
This sample places the custom action used to create a WiseScript following within the MSI Script > Execute Immediate Script:
- Locate the RemoveExistingProduct action within the script. Highlight that area of the script and double-click on the Run WiseScript from Installation custom action.
- The Run WiseScript from installation dialog will appear.
- Click the Options button and choose Create New WiseScript. Once named and saved, WiseScript opens a blank script on the desktop.
- Double-click on the Get Windows Installer Property action to get the COMPANYNAME property and place it into a COMPANYNAME variable. Repeat this step for USERNAME.
- Select the Set Variable custom action and place it after the last Get Windows Installer Property custom action.
- Create a variable that will hold the path to the text file location. Enter the Variable in the Variable field and the path in the Value field.
- Double-click on the Insert Line into Text file action and place it after the Set Variable action. The insert Line into Text File dialog appears.
- Enter the variable created in step 6 enclosed in percent signs followed by a backslash and the name of the file in the File to Edit field.
- In the Text to Insert field, enter any information necessary to be written into the text file including the variable that contain the end user input.
- Enter the line number that you want this information written to. You can also choose to have it written after or before a specific line or to replace a line by populating different fields in the Insert Line into Text file action.
- Wrap the Run WiseScript from Installation custom action in a IF Statement so that it is only run during installation. The portion of the script should look similiar to the following:
Run WiseScript from Installation
Following the above steps creates a dialog that accepts end user input in an .msi installation, then writes the data collected using a WiseScript to a text file it creates on the destination computer.