WiX Tutorials – Add ini file entries and properties in MSI

 

So we learned how to create a basic MSI, add features, components and files, and add shortcuts and registry to an MSI.

Let’s now have a look on how you can create an ini file and add properties to your msi.

 

To create and add an ini we add the following code to the example1.wxs


<DirectoryRef Id="TARGETDIR">
<Directory Id="WindowsFolder">
<Directory Id="Security" Name="Security">
<Directory Id="Templates" Name="Templates">
<Component Id="IniFile1" Guid="11111114-2222-3333-4444-555555555555">
<CreateFolder />
<IniFile Id="Ini1"
Action="createLine"
Directory="Templates"
Section="Test"
Name="Security.ini"
Key="TestKey"
Value="TestValue" />
</Component>
</Directory>
</Directory>
</Directory>
</DirectoryRef>

 

We first create a directory tree in %windir%\Security\Templates. This will be the targetdir of our new component IniFile1 which contains the INI entries.

GUID for these type of components must be specified and cannot be generated via “*”. Because this component does not have a primary key, we have to put the desired folder in the CreateFolder table with <CreateFolder/>.

After that we create a simple Security.ini with a test Key and test Value. Easy right?

Don’t forget to add your component to the feature.

 

Properties are even simpler to add in your MSI


<Property Id="CUSTOM_PROPERTY" Secure="yes" Value="Example">
</Property>

 

Now, our example1.wxs looks like


<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" UpgradeCode="12345678-1111-2222-3333-666666666666"

Name="My First Installer" Version="1.0.0.0" Manufacturer="My Company" Language="1033">
<Package InstallerVersion="200" Compressed="yes" Comments="Hello, this is my first installer"/>
<Media Id="1" Cabinet="product.cab" EmbedCab="yes"/>

<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLDIR" Name="MyFirstInstaller">
<Component Id="Files" Guid="11111111-2222-3333-4444-555555555555">
<File Id="File1" Source="Trace32.exe"/>
</Component>
</Directory>
</Directory>

<Directory Id="ProgramMenuFolder">
<Directory Id="MyShortcut" Name="My First Installer">
<Component Id="Shortcuts" Guid="11111112-2222-3333-4444-555555555555">
<Shortcut Id="Shortcut1" Name="Trace32" Description="Trace32"

Target="[INSTALLDIR]Trace32.exe" WorkingDirectory="INSTALLDIR"/>
<RegistryValue Root="HKCU" Key="Software\My First Installer"

Name="Installed" Type="integer" Value="1" KeyPath="yes"/>
<RemoveFolder Id="MyShortcut" On="uninstall"/>
</Component>
</Directory>
</Directory>
</Directory>

<DirectoryRef Id="TARGETDIR">
<Directory Id="WindowsFolder">
<Directory Id="Security" Name="Security">
<Directory Id="Templates" Name="Templates">
<Component Id="IniFile1" Guid="11111114-2222-3333-4444-555555555555">
<CreateFolder />
<IniFile Id="Ini1"
Action="createLine"
Directory="Templates"
Section="Test"
Name="Security.ini"
Key="TestKey"
Value="TestValue" />
</Component>
</Directory>
</Directory>
</Directory>
</DirectoryRef>

<DirectoryRef Id="TARGETDIR">
<Component Id="Regs">
<RegistryValue Root="HKLM" Key="Software\My First Installer"
Name="Installed" Type="integer" Value="1" KeyPath="yes"/>
</Component>
</DirectoryRef>

<Property Id="CUSTOM_PROPERTY" Secure="yes" Value="Example">
</Property>

<Feature Id="Feature1" Level="1" Title="First feature" Description="This is the one and only feature in this installation">
<ComponentRef Id="Files"/>
<ComponentRef Id="Shortcuts"/>
<ComponentRef Id="Regs"/>
<ComponentRef Id="IniFile1"/>
</Feature>
</Product>
</Wix>

 

Once you edit the example1.wxs, let’s build it. Double-click make_msi.bat, the msi shoult be generated without any problems.

Upon opening the MSI with Advanced Installer, we can see that

our ini file is created as desired, and

our property is set as desired.

 

That is it for this tutorial.

For more information and documentation about WiX, check out this page.

Sharing is caring!

Leave a comment

Your email address will not be published. Required fields are marked *

sixteen + 14 =