Thursday 18 August 2011

Detecting SQL Server from wix installer

When creating an installer using wix (3.5 or later) some times you need to detect if the machine you are installing on has some form of SQL Server installed.

The following check for a 32 bit version of various kinds of SQL Server

<property id="SQLEXPRESS2005">
<registrysearch id="SQLExpress2005"
   key="Software\Microsoft\Microsoft SQL Server\90\Tools\ClientSetup\CurrentVersion"
   name="CurrentVersion"
   root="HKLM"
   type="raw" win64="no">
</registrysearch>
</property>

<property id="SQLEXPRESS2008">
<registrysearch id="SQLExpress2008"
   key="Software\Microsoft\Microsoft SQL Server\Instance Names\SQL"
   name="SQLEXPRESS"
   root="HKLM"
   type="raw"
   win64="no">
</registrysearch>
</property>

<property id="SQLSERVER">
<registrysearch id="SQLServer2005orLater"
   key="Software\Microsoft\Microsoft SQL Server\Instance Names\SQL"
   name="MSSQL"
   root="HKLM"
   type="raw"
   win64="no">
</registrysearch>
</property>

The following check for a 64 bit version of various kinds of SQL Server

<property id="SQLEXPRESS2005X64">
<registrysearch id="SQLExpress2005x64"
   key="Software\Microsoft\Microsoft SQL Server\90\Tools\ClientSetup\CurrentVersion"
   name="CurrentVersion"
   root="HKLM"
   type="raw" win64="yes">
</registrysearch>
</property>

<property id="SQLEXPRESS2008X64">
<registrysearch id="SQLExpress2008x64"
   key="Software\Microsoft\Microsoft SQL Server\Instance Names\SQL"
   name="SQLEXPRESS"
   root="HKLM"
   type="raw"
   win64="yes">
</registrysearch>
</property>

<property id="SQLSERVERX64">
<registrysearch id="SQLServer2005x64orLater"
   key="Software\Microsoft\Microsoft SQL Server\Instance Names\SQL"
   name="MSSQL"
   root="HKLM"
   type="raw"
   win64="yes">
</registrysearch>
</property>

The magic lines are win64="yes" to force a search of the 64 bit registry and win64="no" to search the 32 bit registry.

12/03/2013 Note: I've just noticed that the above bits don't work with WIX 3.7. They need the case of the elements and attributes changing to camel case.

No comments:

Post a Comment