Freigeben über


From MSI to WiX, Part 15 - Installable Items - Ini files

The main page for the series is here.

 

Introduction

Today's topic is how to create and modify Ini files.

MSI story

Ini file contains configuration information that application needs during run-time.

MSI has two tables related to Ini files:  IniFile and RemoveIniFile.   IniFile table contains information about data which need to added to the Ini file on install or removed from the Ini file on uninstall.  RemoveIniFile table describes the data which need to be removed from the Ini file on install.

Two standard actions must be scheduled in the Execute sequence tables: WriteIniValues and RemoveIniValues.

Here is the list of columns of the IniFile table:

Column Description
IniFile The primary key for the table.
FileName

The localizable name of the .ini file in which to write the information.

DirProperty The name of the property which will be resolved to the full path of the folder containg the .ini file.  If this field is blank, the WindowsFolder property will be used to determine the path.
Section

The localizable .ini file section.

Key The localizable .ini file key within the section.
Value

The localizable value to be written.

Action The type of modification to be made.
Component_ External key into the first column of the Component table.

Here is the list of columns of the RemoveIniFile table:

Column Description
RemoveIniFile The primary key for the table.
FileName

The localizable name of the .ini file in which to delete the information.

DirProperty The name of the property which will be resolved to the full path of the folder containg the .ini file.  If this field is blank, the WindowsFolder property will be used to determine the path.
Section

The localizable .ini file section.

Key The localizable .ini file key within the section.
Value

The localizable value to be deleted. The value is required when Action is 4.

Action The type of modification to be made.
Component_ External key into the first column of the Component table.

Removing the last value from a section deletes that section. There is no other way to delete an entire section other than removing all its values.

What we can do with the Ini file 

These are the options we have when we add/delete value:

  • Create a new entry or update it if entry already exist.
  • Create a new entry if it does not exist.
  • Remove entry.
  • Create a new entry or append a tag if entry already exist.
  • Remove a tag from the entry.  If entry becomes empty, it will be removed.

Also, keep in mind that if you delete a last entry in the .ini file, file will be deleted.

How it translates to WiX?

To create/delete entries:

IniFile/Action RemoveIniFile/Action <IniFile> attribute Description
msidbIniFileActionAddLine (0)   Action="addLine" Create or update an .ini entry.
msidbIniFileActionCreateLine (1)   Action="createLine" Create an .ini entry if entry does not exist.
msidbIniFileActionAddTag (3)   Action="addTag" Creates a new entry or appends value to existing entry.
  msidbIniFileActionRemoveLine (2) Action="removeLine" Removes an entry.
  msidbIniFileActionRemoveTag (4) Action="removeTag" Removes a tag from an entry.  If entry's value becomes empty, entry is removed.

Examples

  • Create a new entry if it does not exist: 

     <IniFile Id="Ini1"

              Action="createLine"

              Directory="INSTALLLOCATION"

              Section="Test"

              Name="Minimal.ini"

              Key="TestKey"

              Value="TestValue" />

 Creates this:

[Test]

TestKey=TestValue

  • Add a tag to already existing entry:

     <IniFile Id="Ini1"

              Action="addTag"

              Directory="INSTALLLOCATION"

              Section="Test"

              Name="Minimal.ini"

              Key="TestKey"

              Value="TestValue2" />

Creates this:

[Test]

TestKey=TestValue,TestValue2

  • Remove a tag:

     <IniFile Id="Ini1"

              Action="removeTag"

              Directory="INSTALLLOCATION"

  Section="Test"

              Name="Minimal.ini"

              Key="TestKey"

              Value="TestValue" />

Creates this:

[Test]

TestKey=TestValue2

Here is the sample which installs ini file both in the installation folder and Windows folder.  Code for this sample is attached.

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

<Wix xmlns="https://schemas.microsoft.com/wix/2003/01/wi">

  <?include ..\..\Common\CommonDefinitions.wxi ?>

  <?include Definitions.wxi ?>

  <Product Id="$(var.ProductCode)"

           Name="$(var.ProductName)"

           Language="$(var.Language)"

           Version="$(var.CurrentVersion)"

           Manufacturer="$(var.Manufacturer)"

           UpgradeCode="$(var.UpgradeCode)" >

    <Package Id="$(var.PackageCode)"

             Description="$(var.PackageDescription)"

             Comments="$(var.PackageComments)"

             InstallerVersion="200"

             Compressed="yes"

             Languages="$(var.Languages)" />

    <?include ..\..\Common\ARP.wxi ?>

    <Media Id="1" Cabinet="Product.cab" EmbedCab="yes" />

    <?include ..\..\Common\UpgradeSupport.wxi ?>

    <Directory Id="TARGETDIR" Name="SourceDir">

      <Directory Id="ProgramFilesFolder">

        <Directory Id="INSTALLLOCATION"

                   Name="Minimal"

                   LongName="MinimalInstallation">

          <Component Id="TestIni"

                     Guid="{DC752365-A598-4B76-AC60-C99BF34D539F}">

            <CreateFolder />

            <IniFile Id="Ini1"

                     Action="createLine"

                     Directory="INSTALLLOCATION"

                     Section="Test"

                     Name="Minimal.ini"

                     Key="TestKey"

                     Value="TestValue" />

            <IniFile Id="Ini2"

                     Action="createLine"

                     Directory="WindowsFolder"

                     Section="Test"

                     Name="Minimal.ini"

                     Key="TestKey"

                     Value="WindowsFolder TestValue" />

          </Component>

        </Directory>

      </Directory>

    </Directory>

    <Feature Id="MainFeature"

             Title="TestApp application"

             Level="1">

      <ComponentRef Id="TestIni" />

    </Feature>

  </Product>

</Wix>

 

Part15.zip

Comments

  • Anonymous
    August 20, 2008
    The comment has been removed

  • Anonymous
    August 20, 2008
    I've updated this post to include sample and attachment with this sample.

  • Anonymous
    January 09, 2009
    Hi Alex, I am new with WIX and I am searching for how to make a multilingual .msi installer. Is there any way to do this?

  • Anonymous
    December 30, 2009
    The comment has been removed

  • Anonymous
    April 05, 2012
    @questsid                  <IniFile Id="Ini2"                     Action="createLine"                     Directory="WindowsFolder"                     Section="Test"                     Name="Minimal.ini"                     Key="TestKey"                     Value="[PROPERTYNAMEFOREDITBOXWHICHHASIPVALUE]" />

  • Anonymous
    August 21, 2012
    @ron I think you're a few years too late....

  • Anonymous
    December 13, 2013
    I never know why people jump in and say, "you are a few years too late". I stumbled across this page, and found an answer I was looking for. Now, if our friend Ron here didn't put his answer, I would still be looking. So, just because he jumped in years later, it was unanswered -- that is, until Ron did. So, for that, I applaud him ;o)

  • Anonymous
    January 20, 2014
    I get a 2343 file not found error in uninstall process, when I use inifile element to edit file that I just installed. It seems that in uninstall process Wix tries to restore ini file parameters, but at that time that ini filie is already deleted. Is there any way to control sequence of inifile actions during install and uninstall?