Using an if condition to compare variable values ​​in WiX

I want to check if the user passed an argument for USERNAME for which the default value is local. I am trying to see if I get a message if the value is local. The problem is as follows. This does not 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 next, it will display a 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 the message box.

I tried many scripts and could find where the problem is. When comparing the values ​​of variables that are assigned as,

 <?define uName = [USERNAME]?> 

Although the value is assigned to uName, we cannot perform the comparison. Am I doing something wrong here? Or is there any other way for this kind of problem?

+4
source share
1 answer

Could you do this without 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 the username, then the installation will continue, but if the user does not complete this, he will fail because the default value is local.

I am wondering how the username is entered. Is it through the command line or from the input dialog box?

If in a dialog box - I suggest having a dialog box with an error, and not interrupt the installation. Maybe I'm wrong, but just giving you options.

Hope this helps ... :)

EDIT:

To do what you want, just add a condition to your component that your service is in. You 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> 
+12
source

Source: https://habr.com/ru/post/1469452/


All Articles