Adam Godefroy
Adam Godefroy

Reputation: 45

Check condition and continue installation using Wix Toolset

I have a .wxs file for program installation. I want to pass a part of installation depending on the OS version (for ex. execute if OS verion > XP and pass if <= XP) and continue to install other parts. It means that i've already installed some components, and during the installation want to check (according to the current OS), should i install next component or not. If yes - install, if not - installation of the component should be skipped. Of course, after that full installation should continue. I don't want to abort the installation and remove installed components, just skip one component. How can i do it? Also, I found this one link. There is a block install case, but i want to continue installation after condition. There is another assumption - we can use

<?if *condition* ?> ... <?endif?>

blocks, but i really don't understand how to get OS info there. Any ideas?

Upvotes: 2

Views: 7551

Answers (1)

Brian Sutherland
Brian Sutherland

Reputation: 4798

You don't want to use <?if ... ?> these are preprocessor directives like #ifdef and #ifndef in c++ and just determine whether or not the part between the if is included for compilation or not. This will only be evaluated at built time on the build machine.

Something like this would stop your installation from running on Windows XP or earlier machines.

<Condition Message="!(loc.OSNotSupported)">Installed OR VersionNT &gt; 501 OR VersionNT64 &gt; 501</Condition>

Similar conditions can be used to dictate whether or not a component is installed, a feature is installed, or a custom action is run.

If you update your question and leave a comment on this answer I will try to update my answer to better answer you question.


To install certain components dependent on the OS of the machine you are running is quite simple, just add the following to your <component>

<Component Id="InstallMeOnXP" Guid="*">
    <Condition>VersionNT &lt;= 501 OR VersionNT64 &lt;= 501</Condition>
    <File Id="XPOnly.dll" KeyPath="yes" Source="$(var.BinariesDir)\_bin\XPOnly.dll" />
</Component>

If the condition evaluates to TRUE then the component will be installed, otherwise it will not be installed. More info on the Condition element in wix.

Here is the information about the default VersionNT and VersionNT64 properties for the Windows Installer.

Upvotes: 3

Related Questions