Custom Action execution by feature - wix

I wrote a custom action to create a scheduled task after install.
I do not want the Custom Action to run when the user does not want to create the schedule task. During installation even if I select " Feature will be unAvailable" the schtask is getting created. How do i prevent the Custom Action from executing?

You can set a condition for your CA execution:
<InstallExecuteSequence>
<Custom Action="ScheduleTaskCA" After="InstallFinalize">
<![CDATA[&feature_name=3]]>
</Custom>
</InstallExecuteSequence>
Hope it helps.
If you want to read more about CAs conditions, you can chech the link below.
Advanced Custom Action Conditions

Add to your Install execute sequence.

Actually I found out the problem. The &FeatureName = 3 tells me that the feature is to be installed, and the opposite to that, is !FeatureName = 3, which means the feature is installed already. This fixed my problem so the final solution became
&FeatureName = 3 OR (!FeatureName = 3 AND NOT (Uninstalling OR MSIPATCHREMOVE OR RemovingForUpgrade)

"MyService" is feature Name
"FEATURE_MyService" is my condition Name: I am using checkbox to set the value of FEATURE_MyService property
<Control Id="Chk1" Type="CheckBox" Height="12" Width="110" X="50" Y="199" Text="Portal Windows Service" Property="FEATURE_MyService" CheckBoxValue="0" Hidden="yes">
<Custom Action='CAction1' After="InstallExecute">
NOT Installed AND <![CDATA[(&MyService=3)]]>
<Custom Action='CAction2' Before='InstallExecute'>
<![CDATA[(&MyService=3 AND NOT Installed)]]>
<Custom Action='CAction3' After='InstallFinalize'>
<![CDATA[FEATURE_MyService AND NOT Installed ]]>

Related

WiX customaction doesnot have value for session.Property["CustomActionData"]

I have to pass a value to my custom action in patch release for my feature. I did some research and did the following:
<CustomAction Id="CustomAction1" Property="customaction2" Value="Value1" />
<CustomAction Id="customaction2" BinaryKey="Binary.dll"
DllEntry="Functionname" Impersonate="no"
Execute="immediate" Return="check" />
I also updated the installExecuteSequence as below:
<Custom Action='CustomAction1' After="InstallFinalize"><![CDATA[PATCH]]></Custom>
<Custom Action='customaction2' After="CustomAction1"><![CDATA[PATCH]]></Custom>
I also added the componentrefs to the patch.wxs file.
<CustomActionRef Id="CustomAction1.PackageGuid"/>
<CustomActionRef Id="customaction2.PackageGuid"/>
To access this parameter value, I tried the following code in my customaction "Functionname" :
var value = session.Property["CustomActionData"];
The "value" is Empty. I did some debugging and found that, i am getting the value from below code:
var value = session.Property["customaction2.PackageGuid"];
I have not seen any examples that access properties with packageGuids also. I am not sure why the first approach(using "CustomActionData") is not working for me.
Can you guys let me know what i am missing?
Also, Is there any harm in using with packageGuids? If not, i am planning to continue this way. Please let me know if you need me to try any other st

WIX The properties modified in the custom action are not correct in the exit dialog

I need to determine if the user has installed SQL during the installation phase, and if the user is not installed, the check box for installing SQL is displayed in the exit dialog box.
I defined a variable called IS_INSTALL_SQL with an initial value of 0. In the custom action, I will determine whether the user has installed SQL based on the registry, and if not installed, the IS_INSTALL_SQL is set to 1.
According to the log, IS_INSTALL_SQL is set to 1, but in the exit dialog box, the value is still 0 and the check box is not displayed.
The following is the code
[product.wxs]
<Property Id="IS_INSTALL_SQL" Value="0"/>
<Binary Id="myCustomActionsDLL" SourceFile= "$(var.CustomAction1.TargetDir)CustomAction1.CA.dll" />
<CustomAction Id="checkSQLInstallAndVersion" BinaryKey="myCustomActionsDLL" DllEntry="checkSQLInstallAndVersionAction" Execute="immediate" Return="check"/>
<InstallExecuteSequence>
<Custom Action="checkSQLInstallAndVersion" Before="InstallValidate">NOT Installed</Custom>
</InstallExecuteSequence>
[ExitDialog.wxs]
<Control Id="InstallSQLCheckBox"
Type="CheckBox"
X="135"
Y="170"
Width="220"
Height="14"
Hidden="yes"
Property="WIXUI_EXITDIALOGOPTIONALCHECKBOX_SQL"
CheckBoxValue="1"
Text="[WIXUI_EXITDIALOGINSTALLSQLTEXT]" >
<Condition Action="show">
<![CDATA[IS_INSTALL_SQL = "1" AND NOT Installed]]>
</Condition>
</Control>
The following is a log snippet.
Line 86: MyLog:The SQL version is below the minimum version
requirement and enters the installation SQL step.
Line 87: MyLog:#IS_INSTALL_SQL#:0
Line 88: MyLog:Set Property Value
Line 89: MyLog:#IS_INSTALL_SQL#:1
Line 187: Property(S): IS_INSTALL_SQL = 1
Line 317: Property(C): IS_INSTALL_SQL = 0
You only schedule the CA during InstallExecuteSequence which happens after the UI phase. Schedule it early in both, including InstallUISequence and sequence it before AppSearch, then define the CustomAction #Execute="firstSequence" for example so it only runs once and sets the value appropriately. While you have it defined as public (all upper case including underscores), ensure that doesn't change otherwise its value is reset to its default of 0 in your case when the client phase ends and the server phase starts.

How to define a CustomAction with a long command line in WIX?

I have define a custom action in my wxs file:
<CustomAction ExeCommand="long command line" FileKey="xyz.exe" Id="foo"/>
and I receive the warning:
warning LGHT1076 : ICE03: String overflow (greater than length
permitted in column); Table: CustomAction, Column: Target, Key(s):
What is the right solution to define an action with a long command line?
After many time I have find a solution. I split the command line into multiple properties.
<CustomAction Id="action.prop0" Property="prop0" Value="first part with [INSTALLDIR]"/>
<CustomAction Id="action.prop" Property="prop" Value="[prop0] second part"/>
<CustomAction ExeCommand="[prop]" FileKey="service.exe" Id="myaction"/>
<InstallExecuteSequence>
<Custom Action="action.prop0" After="InstallFiles"/>
<Custom Action="action.prop" After="action.prop0"/>
<Custom Action="myaction" Before="InstallFinalize"/>
</InstallExecuteSequence>
Assign the long command line to a property and then use [PROPERTY] in the custom action. Although EXE custom actions in general are frowned upon. If you must do it use the WiX Quiet Execute Custom Action feature.

Set property value based on condition in WiX

I searched through several questions at Stack Overflow, but nothing helped me. The problem is:
I look in the registry for some value (I know how to do that). I know how to set property. But I cannot find the way how to write this expression in WiX. This is what I want to write in pseudocode:
if(registryvalue contains substring1)
set property to value1
if(registryvalue contains substring2)
set property to value2
This condition must be evaluated at runtime. Is there a way to write this condition? What would some sample code look like?
You can use a type 51 custom action to set the property:
<CustomAction Id="SET_VALUE1" Property="TEST_PROPERTY" Value="value1" />
<CustomAction Id="SET_VALUE2" Property="TEST_PROPERTY" Value="value2" />
Use the condition when you call the custom action in install sequences:
<Custom Action="SET_VALUE1" After="AppSearch">Not Installed AND (REG_VALUE="substring1")</Custom>
<Custom Action="SET_VALUE2" After="AppSearch">Not Installed AND (REG_VALUE="substring2")</Custom>
Or you can write the custom actions in managed code like C#, and schedule it after AppSearch in case you have many comparisons.

Execute a custom action before Product condition

Basically I need to verify that a certain program is not running before installation. This is done via a custom action, which sets a property, APPRUNNING:
<CustomAction Id="CheckingAppIsRunning"
BinaryKey="AppIsRunning"
DllEntry="AppIsRunning"/>
<Binary Id="AppIsRunning"
SourceFile="CustomActions.CA.dll" />
But in the message displayed, APPRUNNING seems to be null, that is, it's not set at all (should be either "0" or "1").
<Condition Message="Exit all instances of [APPNAME] before installation (APPRUNNING = [APPRUNNING]).">
<![CDATA[APPRUNNING = "0"]]>
</Condition>
<InstallExecuteSequence>
<Custom Action="CheckingAppIsRunning" Before="LaunchConditions" />
</InstallExecuteSequence>
I suppose the custom action is not executed at the moment of the condition check. What are the options to perform a condition check after a custom action?
The LaunchConditions action is scheduled to run in both InstallUISequence and InstallExecuteSequence. As long as you schedule your custom action to InstallExecuteSequence only, the property won't be set by the time LaunchConditions is fired in InstallUISequence.
You should schedule your CheckingAppIsRunning custom action in both sequences. You might also want to define it with Execute='firstSequence' attribute - this way it will run the first sequence it is met in.
This is what I mean, actually:
<InstallUISequence>
<Custom Action="CheckingAppIsRunning" Before="LaunchConditions" />
</InstallUISequence>
<InstallExecuteSequence>
<Custom Action="CheckingAppIsRunning" Before="LaunchConditions" />
</InstallExecuteSequence>
And the definition:
<CustomAction Id="CheckingAppIsRunning" BinaryKey="AppIsRunning" DllEntry="AppIsRunning" Execute="firstSequence"/>