CLINI.EXE

The Command Line INI utility (clini.exe) can write information to and read information from an INI file, as well as merge information from one INI file with another.

The Command Line INI utility can perform the following functions:
Two versions of the Command Line INI utility come with the ServerGuide Scripting Toolkit:
Storing a value as an environment variable is done by creating a batch file that contains a command to set the environment variable. You must then call the batch file to set the environment variable. By default, the batch file is named cliniset.bat. If the batch file already exists, it is deleted and recreated with the new information.
Note: Because the media is read-only, this feature cannot be used on a bootable Windows PE CD or DVD.

In addition to setting values, the clini.exe program can append values to existing items in an INI file. By default, no delimiter is used to append values. A delimiter can be specified, if required. Appending values provides the ability to ‘build' values in the INI file by issuing multiple commands. When reading values from an INI file to set an environment variable, the values can be tokenized to specify a particular token.

The clini.exe program checks the number of characters on the command line and displays a message if the characters exceed the limit. The /O parameter overrides character-limit checking.

The clini.exe utility has the following command-line syntax:
clini <filename> <[filename2 [/ES] [/A|/U|/P]]> <[/S:section] 
[/I:item] [/V:value|/A:value|/U:value|/E:variable
|/=:string|/C:string|/CT:string]> [/B:file_name] 
[/D:delimiter] [/T:n] [/R] <[/CMT|/UCMT| [/AI] 
[/CC:character]]> [/NS] [/N] [/O] 
Parameter Description
filename
Defines the fully qualified path to the INI file to process.
filename2		
Defines the fully qualified path to an INI file to merge information into from filename. All values in filename are copied into filename2, replacing the value of any preexisting items in filename2.
/ES	
Specifies to merge only the items or values in the empty section.
/A	
Specifies to append values from items in filename to the items in filename2 instead of replacing them. An optional delimiter can be specified using the /D:delimiter parameter.
/U	
Specifies to uniquely append values from items in filename to the items in filename2 instead of replacing them; only if the value doesn't already exist. An optional delimiter can be specified using the /D:delimiter parameter.
/P Specifies that the data in filename2 is persistent. If duplicate items are found, they are not replaced.
/S:section
Specifies the name of the section within the INI file to write or to read.
/I:item
Specifies the name of the item within the INI file to write or to read.
/V:value
Specifies the value to write to the INI file.
/A:value
Specifies the value to append to the existing item in the INI file. The /I parameter is required to use the /A:value parameter.
/U:value
Specifies a unique value to append to the existing item in the INI file, only if this value does not already exist for the item. The /I parameter is required to use the /U:value parameter.
/E	
Convert multiple Items to Environment Variables. The Item name is used for the environment variable name. Use the /NS parameter to replace any spaces in the item names with underscore characters when creating the Environment Variables, if spaces are not desired.
/E:variable
Specifies the environment variable used to store the value of the item from the INI file. The /I parameter is required to use the /E:variable parameter. If the item specified by the /I parameter does not exist, or the section specified by the /S parameter does not exist, the environment variable has no value in the batch file created by clini.exe. If the environment variable exists on the system, it is deleted when the batch file runs.
/=:string
Verifies that the value of the item is equal to string, returning a value of 0 if true and 100 if false.
/C:string
Verifies that value of the item has string as a substring, returning a value of 0 if true and 100 if false.
/CT:string
Verifies that the value of the item has string as one of the tokens, returning a value of 0 if true and 100 if false. The default delimiter is a comma unless the /D:delimiter option is specified.
/B:filename
Defines the fully qualified path and file name of the batch file to create for setting the environment variable. The default is CLIniSet.bat if no file name is specified for this parameter. This parameter is only valid when the /E parameter is used.
/D:delimiter
Specifies a delimiter to use when appending values to an item in an INI file or reading tokens from an INI file. This parameter is not valid if the /V parameter is used. The /D parameter is valid only with the /A, /U, or /E parameters. Using the /D parameter without one of these three parameters results in a syntax error.
/T:n
Specifies the token in a delimited value to set as the specified environment variable, where n is a positive integer. The default delimiter is a comma unless otherwise specified with the /D parameter. This parameter is only valid with the /E parameter.
/R
Removes the specified section, item, or value from the INI file. Removing the last item in a section also removes the section.
/CMT	
Specifies to comment out the line indicated by the Section, Item, or Value parameter, if it exists in the INI file. It also allows use of the /AI parameter.
/UCMT
Specifies to Uncomment the line indicated by the Section, Item, or Value parameter, if it exists in the INI file. It also allows use of the /AI parameter.
/CC:character	
Specifies the comment character to use when commenting or uncommenting lines. If omitted, the default comment character is the semicolon. This parameter is only valid with the /CMT or /UCMT parameters.
/AI	
Specifies to explicitly treat the /V parameter as the value to all items when commenting or uncommenting. This parameter is only valid when using the /CMT or /UCMT parameters.
/N
Deletes an existing INI file and creates a new INI file. This parameter is not valid with the /E parameter.
/NS
Omits spaces around "=" when writing items into INI files. By default, the clini.exe utility concatenates spaces around "=" when writing items.
/O
Overrides the command-line character count. The number of characters on the command line is automatically determined by this utility. An error message is displayed when the character limit is reached, unless you override this feature. The Windows command line is limited to 8189 characters.
The clini.exe utility returns the following values to indicate status:
Value Description
0 Success or true
1 Syntax error
2 Program error
3 Destination is read-only
4 Current working directory is read-only.
5 File not found
100 False
The following examples illustrate Command Line INI utility usage.
Example Description
clini info.ini /S:Hardware /I:Machine Type 
/V:8549 /N
Deletes any existing info.ini file and creates a new INI file named info.ini with a section called Hardware that contains one item, Machine Type, which has a value of "8549."
clini info.ini /S:Hardware 
/I:Machine Name /V:Server1
Adds the item Machine Name with a value of Server1 to the existing Hardware section of the info.ini file
clini info.ini /S:Hardware 
/I:Machine Type /E:MachineType

call CLIniSet.bat
Reads the Machine Type value from the info.ini file, and stores it as an environment variable called MachineType.
clini info.ini /S:Hardware /I:Machine Type2
/V:%MachineType%
Writes the value of the environment variable MachineType to the INI file named info.ini, using section Hardware and item Machine Type2.
clini info.ini /S:Hardware /I:Machine Type2
/E:MachineType2 /B:d:\EnvSet1.bat

call d:\EnvSet1.bat
Reads the machine type value from the info.ini file and stores it as an environment variable called MachineType2 using a custom path and name for the batch file created to set the environment variable.
Clini info.ini /S:MySection /E  

Call cliniset.bat	
This example creates environment variables for all the items found in section MySection.
Clini info.ini /AI /E /B:setthem.bat

Call setthem.bat	
This example creates environment variables for all the items found in any section of the info.ini file and uses an alternate name for the CLIniSet.bat file.
Clini info.ini /S:MySection /I:MyItem /E

Call cliniset.bat	
This example creates an environment variable called MyItem if it exists in the info.ini file.
Clini info.ini /S:MySection /I:My Item /E /NS  

Call cliniset.bat	
This example creates an environment variable called My_Item (converts the space to an underscore for the environment variable name) if the item exists in the info.ini file.
After running the first five examples above, in sequence, the info.ini file contains the following information:
[Hardware]
Machine Type = 8549
Machine Type2 = 8549
Machine Name = Server1
Also, two new environment variables are created, as shown below:
MachineType = 8549
MachineType2 = 8549
clini info.ini /S:User /I:Name /V:Toolkit /N
clini info.ini /S:User /I:Name /A: User

or

clini info.ini /S:User /I:Name /V:Toolkit /N
clini info.ini /S:User /I:Name /A:User /D:" "
Creates a new file named info.ini with a section called User and one item called Name, which is set equal to "Toolkit User". The resulting info.ini file contains:
[User]
Name = Toolkit User
clini info.ini /S:Section /I:Item /A:Value1 /D:, /N
clini info.ini /S:Section /I:Item /A:Value2 /D:,
clini info.ini /S:Section /I:Item /A:Value3 /D:,
clini info.ini /S:Section /I:Item /A:Value2 /D:,
Creates a new file named info.ini with a comma delimited list of values. The resulting info.ini file contains:
[Section]
Item = Value1,Value2,Value3,Value2
clini info.ini /S:Section /I:Item /U:Value1 /D:, /N
clini info.ini /S:Section /I:Item /U:Value2 /D:,
clini info.ini /S:Section /I:Item /U:Value3 /D:,
clini info.ini /S:Section /I:Item /U:Value2 /D:,
Creates a new file named info.ini with a comma delimited list of unique values. The resulting info.ini file contains:
[Section]
Item = Value1,Value2,Value3
clini info.ini /S:Section /I:Item /E:MyEVariable
/T:2

or

clini info.ini /S:Section /I:Item /E:MyEVariable
/T:2 /D:,
Reads information from the info.ini file created in the previous example, and sets the second value of the item to the MyEVariable environment variable. The resulting CLIniSet.bat file contains:
Set MyEVariable=Value2
Content of doit.bat:

@Echo off
clini info.ini /S:Secton /I:Item /V:Value1 /N
clini info.ini /S:Section /I:Item /=:Value1
if errorlevel 100 goto itsfalse
if errorlevel 1 goto error
if errorlevel 0 goto itstrue
:error
Echo Error occurred
Goto end
:itsfalse
Echo It's false
Goto end
:itstrue
Echo It's true
:end
This example creates a file called info.ini with the following content:
[Section]
Item = Value1

Then it checks to see if the value of Item in [Section] is equal to Value1 and displays a message.

After running doit.bat, the follow message is displayed:
It's true
Content of doit.bat:

@Echo off
clini info.ini /S:Section /I:Item /V:Value1 /N
clini info.ini /S:Section /I:Item /C:alu
if errorlevel 100 goto itsfalse
if errorlevel 1 goto error
if errorlevel 0 goto itstrue
:error
Echo Error occurred
Goto end
:itsfalse
Echo It's false
Goto end
:itstrue
Echo It's true
:end
This example creates a file called info.ini with the following content:
[Section]
Item = Value1

Then it checks to see if the value of Item in [Section] contains substring alu and displays a message.

After running doit.bat, the follow message is displayed:
It's true
Content of doit.bat:

@Echo off
clini info.ini /S:Section /I:Item /V:V1,V2,V3 /N
clini info.ini /S:Section /I:Item /CT:V2
if errorlevel 100 goto itsfalse
if errorlevel 1 goto error
if errorlevel 0 goto itstrue
:error
Echo Error occurred
Goto end
:itsfalse
Echo It's false
Goto end
:itstrue
Echo It's true
:end
This example creates a file called info.ini with the following contents:
[Section]
Item = V1,V2,V3

Then it checks to see if the value of Item in [Section] contains token V2 in a comma delimited list and displays a message.

After running doit.bat, the follow message is displayed:
It's true
Clini info1.ini info2.ini
This example copies all the sections, items, and values from info1.ini into info2.ini. Any existing values for items in info2.ini are replaced.
Clini info1.ini info2.ini /P	
This example copies all the sections, items, and values from info1.ini into info2.ini. Any values for existing items in info2.ini are kept. Only new items and values are copied over from info1.ini.
Clini info1.ini info2.ini /S:MySection	
This example copies all the items and values from the section called MySection in info1.ini into the section called MySection in info2.ini replacing any values that may already exist in the section called MySection in info2.ini.
Clini info1.ini info2.ini /S:MySection /I:MyItem	
This example copies the value from the section called MySection, for the Item called MyItem in info1.ini into the same section and item in info2.ini replacing the existing value in info2.ini if it already exists.
Clini info1.ini info2.ini /ES	
This example copies all the items and values from the empty section (items and values that are not in a section) in info1.ini into info2.ini replacing any existing Items in the empty section in info2.ini.
Clini info1.ini info2.ini /A	
This example appends all the values from the sections and items from info1.ini to info2.ini.
Clini info1.ini info2.ini /U	
This example uniquely appends all the values from the sections and Items from info1.ini to info2.ini if the value does not already exist in info2.ini.
Clini info1.ini info2.ini /U /D:	
This example uniquely appends all the values from the sections and items from info1.ini to info2.ini using a comma as the delimiter if the value does not already exist in info2.ini.
Clini info.ini /V:My Ini Line /CMT	
This example comments out the line My Ini Line in the empty section in the info.ini file with a semicolon if the line exists.
Clini info.ini /S:MySection /V:My Ini Line /UCMT	
This example uncomments the line My Ini Line in the MySection section of the info.ini if the line exists.
Clini info.ini /I:MyItem /CMT	
This example comments out the line indicated by the item MyItem in the empty section of the info.ini file if the item exits.
Clini info.ini /S:MySection /I:MyItem /CMT /CC:#	
This example comments out the line indicated by the item MyItem in the section MySection in the info.ini file with a # sign if the item exists.
Clini info.ini /s:MySection /AI /V:My Value /CMT	
This example comments out the lines indicated by any item that has a value of My Value of all the items in the section MySection in the info.ini file if the item exists.
Clini info.ini /s:MySection /CMT	
This example comments out the section header indicated by MySection in the info.ini file if the section exists.