Using if condition to compare variable values in WiX
Asked Answered
D

1

5

I want to check whether the user has passed an argument for USERNAME for which the default value is local. I am trying to see if I I get a message if the value is local. The problem is in the following way. This doesn't work.

<Property Id="USERNAME" Value="local"/>
<?define uName = [USERNAME]?>

<?if $(var.uName) = local ?>
      <Condition Message="$(var.uName)">0</Condition>
<?endif?>

But, if I change the code to the following it will give the message.

<?define uName = local?>

<?if $(var.uName) = local ?>
      <Condition Message="$(var.uName)">0</Condition>
<?endif?>

And the following code assigns the value of the USERNAME property to the uName variable.

<Property Id="USERNAME" Value="local"/>
<?define uName = [USERNAME]?>
<Condition Message="$(var.uName)">0</Condition>

The above code prints 'local' in a message box.

I tried many scenarios and could locate where the problem is. When comparing variable values, which is assigned as,

<?define uName = [USERNAME]?>

Though the value is assigned to uName, we can't do the comparison. Am I doing anything wrong here? Or is there another way for this kind of problem?

Dorelle answered 15/3, 2013 at 9:18 Comment(0)
S
14

Could you do it like this without the variables?

<Property Id="USERNAME" Value="local"/>

<Condition Message="The username is local, please enter a username for the installation to proceed">USERNAME = "local"</Condition>

This would be correct if the user entered a username, then the installation would proceed but if the user did not then it would fail as the default is local.

I do wonder how the username is entered. Is this via the command line or from an input dialog?

If from a dialog - I would suggest having an error dialog rather than aborting the installation. I may be completely wrong but just giving you options.

Hope this helps...:)

EDIT:

To do what you want, simply add a condition to your component which has your service inside. Have two components:

<Component Id="ServiceOne" Guid='*' Directory="Directory">
 //All your service tags etc 
  <Condition><![CDATA[USERNAME = "local"]]></Condition>
</Component>

<Component Id="ServiceTwo" Guid='*' Directory="Directory">
 //All your service tags etc 
  <Condition><![CDATA[USERNAME <> "local"]]></Condition>
</Component>
Selfinduced answered 15/3, 2013 at 11:27 Comment(1)
Hi Natalie, Thanks for the idea, But what I want is, if user enters the value for USERNAME (in command line) it should install a service in a custom account, if not the service should install in local system. I want to filter whether the user has mentioned USERNAME or not, to install the service in correct accountDorelle

© 2022 - 2024 — McMap. All rights reserved.