Get full qualified host name in WIX

In one of our install we need to know the full qualified computer name during installation. For that purpose I did create an custom action with a simple vbscript that simple get the computer name and domain name and create the full qualified string and set property FQDN accordingly.

<CustomAction Id="FindHostDomain" Script="vbscript" Return="check">
  <![CDATA[
  Dim Info
  Set Info = CreateObject("AdSystemInfo")
  Dim InfoNT
  Set InfoNT = CreateObject("WinNTSystemInfo")
 
  Session.Property("FQDN") = lcase(InfoNT.ComputerName & "." & Info.DomainDNSName)
  ]]>
</CustomAction>

To execute this script and set FQDN so we can use it in our component’s add this to the install execution sequence.

<InstallExecuteSequence>
  <Custom Action="FindHostDomain" Before="CostInitialize" >Not Installed</Custom>
</InstallExecuteSequence>

HowTo add new key to appsettings with WIX

When adding a new key for appsettings you need to split the action in 3 steps.
1. Create the new empty “add” element
2. Create and set the “key” attribute. The tricky part here is how to add the “key” to new created “add” element from step one. One way is to assume that the new created “add” element is the only element without a “key” attribute
3. Create and set the “value” attribute.

<util:XmlFile 
  Id='conf1' 
  Action="createElement" 
  ElementPath="//configuration/appSettings" 
  Name="add" 
  File="[INSTALLDIR]Web.config" 
  Sequence="1" />
<util:XmlFile 
  Id='conf2' 
  Action="setValue" 
  ElementPath="//configuration/appSettings/add[\[]not(@key)[\]]"
  Name="key" 
  Value="NewConfig" 
  File="[INSTALLDIR]Web.config" 
  Sequence="2" />
<util:XmlFile 
  Id='conf3' 
  Action="setValue" 
  ElementPath="//configuration/appSettings/add[\[]@key='NewConfig'[\]]"
  Name="value" 
  Value="the new value" 
  File="[INSTALLDIR]Web.config"
  Sequence="3" />

HowTo to set appsettings during installation using WIX

The point where most people have a hard time is remembering is to escape brackets. This to ensure WIX will not think it a property. If you forget to-do this you may end up in a situation where “config2” value will bet set on “config1” instead. See a correct example bellow

[ should be [\[]
] =should be [\]]

<Component Id='UpdateConfig' Guid='A89D47AF-7DBE-4a8d-9848-F35C78FD95ED' DiskId='1' KeyPath="yes">
  <util:XmlFile Id='config1' 
                Action="setValue" 
                ElementPath="//configuration/appSettings/add[\[]@key='FirstKey'[\]]/@value"
                File="[INSTALLDIR]Web.config" 
                Value="[NEWVALUE1]" />
  <util:XmlFile Id='config2' 
                Action="setValue" 
                ElementPath="//configuration/appSettings/add[\[@key='SecondKey'[\]]/@value"
                File="[INSTALLDIR]Web.config" 
                Value="[NEWVALUE2]" />
</Component>

And the example web.config

<?xml version="1.0"?>
<configuration>
  <appSettings>
    <add key="FirstKey" value="oldvalue"/>
    <add key="SecondKey" value="oldvalue"/>
  </appSettings>
</configuration>