There are many ways to edit an INI file in the machine. Following article describes editing INI file using WiseScript. Using WiseScript one can Add/modify/delete a section and its content.
Introduction
INI files are simple text files with a basic structure that contain configuration information. They are commonly associated with Microsoft Windows, but are also used on other platforms. The name "INI file" comes from the filename extension usually used, ".INI", that stands for "initialization".
Format of .INI Files
INI files contain one or more sections. Each section begins with a section name, which is followed by zero or more entries. An entry associates a keyname with a value.
The general format is:
[section]
keyname=value
Comments can also be included in the file by prefacing the comment with a semicolon (;)
Step by step Guide to Edit INI files Using WiseScript
Start Wise Package Studio then open WiseScript Package Editor by double-clicking.
Click the Script Editor tab.
Select Set Variable under All Items in script editor tab.
Double-click on
Set Variable
Set Variable
This action sets the value of a variable by providing a literal value, by modifying the variable's existing value, or by evaluating an expression.
Variable: Specify a variable. A variable name must begin with a letter, must contain only numbers, letters, and underscore characters, and must be 28 characters or less. It should not be enclosed in % signs.
New Value: Enter the new value of the variable. If you enter a variable, enclose it in % signs. The value of a variable can be up to 32K in size.
To complete the dialog fill in the information:
Variable: MYVARIABL
New Value: C:
Here I would like to edit Ini (MyApp.ini) file which is located at "C:\Program Files\My Application\MyApp.ini"
By changing the following values as highlighted in [GUID] section
WindowWidth=380
WindowHeight=96
Select Edit INI File under All Items in script editor tab
Double-click on Edit INI File
Edit INI File
This action edits an .INI file on the destination computer. When a WiseScript is called by a Windows Installer installation, you also can edit an .INI file on the Features or Components tabs of Setup Editor in Windows Installer Editor.
Note: When a WiseScript is called by a Windows Installer installation, the Windows Installer installation does not recognize changes that the WiseScript makes to the destination computer and will not uninstall them. Therefore, you must provide a way to uninstall or repair such changes.
To complete the dialog following information is required:
- File: Enter the .INI file path, or select a path from the list and edit it.
- INI File Contents: Enter changes to make in the .INI file.
Changes are interpreted as follows:
To add to a section, type the section name in brackets, then type new lines for that section. If the .INI file already contains a name-value pair that you type, the existing line is replaced by the new one. Example:
[SECTIONNAME]
Name=value
To delete a section and its contents, type a section name with no lines after it. Example:
[SECTIONNAME]
To delete a name-value pair, type the name with an equals sign followed by nothing. Example:
Name=
Comments (lines starting with ;) are not supported.
To complete the dialog fill in the information
File:
%MYVARIABL%\Program Files\My Application\MyApp.ini
INI File Contents:
[GUI]
WindowWidth=500
WindowHeight=200
Note: Here I would like to change WindowWidth from 380 to 500 and WindowHeight from 500 to 200.
This is just an example.
Click Ok to close the dialog
This is the simple way of editing INI file with two line of code using WiseScript, this can done using VBscript.
Once finished, Save the WiseScript and then compile the script.
Once you run the WiseScript, it will edit the [GUI] Section with the values as desired.
WindowWidth=500
WindowHeight=200
Good luck.
Thanks,
Sid