Table of Contents

IT:AD:WiX:HowTo:Create pre-launch Conditions

Why

It's rather useful to check the target environment before even bothering with an install. The two most common prechecks are

Does the target have the right OS? Does the target have the right .NET Framework? One way to do that is with the use of Condition element.

Process

Placement

Conditions change behavior depending on where they are placed:

<Component|Control|Feature|Product>

*

Feature

> `COndition`: becomes a Condition entry.

*

Product

> `Condition`: becomes a LaunchCondition entry.

For example, a couple of Conditions placed under the Product element:

<Product …

>

      ...
      <!-- Launch conditions -->
      <Condition Message="This application is only supported on Windows Vista, 
                          Server 2008, or higher (32 or 64 bit).">
          <![CDATA[Installed OR (VersionNT >= 600) OR (VersionNT64 >=600)]]>
      </Condition>
      <Condition Message="This application is only supported on Windows Vista, 
                          Server 2008 (32 or 64 bit).">
          <![CDATA[Installed OR (VersionNT < 700) OR (VersionNT64 < 700)]]>
      </Condition>
  </Product>

Common Conditions

#### Platform Check is WS2008+ or Vista, 32 or 64bit ####

<Component|Control|Feature|Product> <Condition Message=“This application is only supported on Windows Vista, Server 2008, or higher (32 or 64 bit).”

>

          <![CDATA[Installed OR (VersionNT >= 600) OR (VersionNT64 >=600)]]>
      </Condition>
  </Component|Control|Feature|Product>

#### Check for the .NET Framework ####
To check for the .NET Framework is nearly the same thing – except that you need variables that are only defined once you've included the NetFxExtensions.

So

Code:

<PropertyRef Id="NETFRAMEWORK20"/>

* Add the Condition that checks one or more of the vars defined in NetFxExtension

Code:

<Condition Message="This application requires .NET Framework 3.0 SP1. 
                Please install then try again.">
    <![CDATA[Installed OR (NETFRAMEWORK30_SP_LEVEL and NOT NETFRAMEWORK30_SP_LEVEL = "#0")]]>
</Condition>

Vars you could check on are:

NETFRAMEWORK20 (will be '#1' if Installed)
NETFRAMEWORK20_SP_LEVEL (will be '#0', or '#1', or...)
NETFRAMEWORK30
NETFRAMEWORK30_SP_LEVEL
NETFRAMEWORK35
NETFRAMEWORK35_SP_LEVEL
NETFRAMEWORK40FULL
NETFRAMEWORK40FULL_SERVICING_LEVEL
NETFRAMEWORK40CLIENT
NETFRAMEWORK40CLIENT_SERVICING_LEVEL

Condition: Check if IIS is installed

You need a Property to return a value from the Registry:

<Property Id="IIS_MAJOR_VERSION">    
    <RegistrySearch Id="_conditionIISVersion"          
              Root="HKLM"              
              Key="SOFTWARE\Microsoft\InetStp"
              Name="MajorVersion"                     
              Type="raw" />
</Property>

That you then reference in a Condition:

<Condition Message="IIS must be installed.">
    Installed OR IIS_MAJOR_VERSION
</Condition>

#### Condition: Check if IIS6 Metabase Compatibiltiy is Installed ####

You need a Property to return a value from the Registry:

<Property Id="IIS_METABASE_COMPAT">    
   <RegistrySearch Id="CheckIISMetabase"                     
              Root="HKLM"
              Key="SOFTWARE\Microsoft\InetStp\Components"
              Name="ADSICompatibility"                     
              Type="raw" />
</Property>

That you then reference in a Condition:

<Condition Message="IIS 6 Metabase Compatibility must be installed.">    
   Installed OR ((VersionNT &lt; 600) OR IIS_METABASE_COMPAT)
</Condition>
 

Resources

* Installed Variable