How do I write text into a file?Answer
Sometimes the installation package must write some information into a file installed by your package. This can be done by using a custom action which calls the OpenTextFile method. Lets suppose that after the installation is complete you want to have a file which contains the serial number entered by the user. This serial number is stored in the SERIAL_NUMBER property which is assigned to an edit box control on a custom dialog. Configure the fileFirst you need to add the file into the Files and Folders page in the folder you want to install it. Since the user can configure the installation folder, you need to set the path of the file into a public property. For this, you go to the Custom Actions page and create a new Property Source custom action under InstallExecuteSequence -> Install. The custom action can use these fields:
Basically, this custom action sets the "SERIAL_FILE" property to the path of the "serial.txt" folder. In this example the file is placed in "Application Folder". Configure the custom actionA simple VBScript custom action which writes the information in the text file is this:
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, f
Dim tokens
Dim file
file=Session.Property("CustomActionData")
tokens=Split(file,"|")
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(tokens(0), ForWriting, True)
f.Write tokens(1)
f.CloseYou can add this custom action as a "New Attached Custom Action" under InstallExecuteSequence -> Install. Also, you can use these settings:
The custom action uses the file variable to get the [SERIAL_FILE]|[SERIAL_NUMBER] string which contains the path of the file, a pipe character ("|") and the serial number. The pipe character is used to parse the string and set multiple installer properties from it. The tokens variable is used to split the string into two values: the path of the file (tokens(0)) and the serial number(tokens(1)). This How-to writes data into a file installed by your package. If you want to create the file with the custom action you can use the CreateTextFile method. | |
|
| Privacy Policy | Windows Installer | Search Engine Ranking | Link Analyzer | ||
| © 2002 - 2008 Caphyon Ltd. Trademarks belong to their respective owners. All rights reserved. | ||