cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Avner_Kashtan
Level 4

Checking for Feature installation in InstallScript/BasicMSI

I have been finding it frustratingly difficult to ascertain in an InstallScript script whether a certain feature is being installed or not.

I have a script that runs on installation and uninstallation. It's supposed to see which features were selected and install a Windows service for that feature.

At first I tried using FeatureIsFeatureSelected(), but that apparently works only in InstallScript projects, and always returns TRUE in Basic MSI projects.

Now I'm trying to use MsiEvaluateCondition, like this:

if (MsiEvaluateCondition(hMSI, "&ParentFeature\\SubFeatureA=3")) then  
MessageBox("Installing FeatureA", INFORMATION);
elseif (MsiEvaluateCondition(hMSI, "&ParentFeature\\SubFeatureA=2")) then
MessageBox("Removing FeatureA", INFORMATION);
endif;


However, this is also returning TRUE in all conditions, both during installation and uninstallation.

What am I doing wrong here?
Labels (1)
0 Kudos
(8) Replies
RobertDickau
Flexera Alumni

Perhaps try this:

MsiEvaluateCondition(hMSI, "&SubFeatureA=3")

Unlike InstallScript, where (I think) features and subfeatures can have the same name, MSI internal feature names must be unique, and so you don't need the fully qualified name in the condition.
0 Kudos
Avner_Kashtan
Level 4

I'm afraid that didn't do the trick. Still getting True.
Tried running it as Immediate, Deferred and Commit - same response for all. When is it supposed to run?
0 Kudos
RobertDickau
Flexera Alumni

Please see the MSI help topic "Conditional Statement Syntax"; in general, feature and component action and state conditions need to be used after CostFinalize.
0 Kudos
MichaelU
Level 12 Flexeran
Level 12 Flexeran

Also note that MsiEvaluateCondition has four possible return values, which per standard integer interpration means three of the four evaluate in an if as TRUE. I think MSICONDITION_FALSE was the sole FALSE one, so MSICONDITION_ERROR might be incorrectly considered TRUE in your code.
0 Kudos
Avner_Kashtan
Level 4

That might be it. I'll check it now (damn the different syntax for IS functions and MSI functions!).

Is there a quicker way of doing this iterative code-compile-check cycle without running a full build for my project. It's a 1-2 minute build process every time. Is there an interactive debugger I can attach to a running installation?
0 Kudos
Avner_Kashtan
Level 4

Apparently the MsiEvaluateCondition is returning MSICONDITION_ERROR (3). I don't know how to check what the error is. The documentation doesn't list MsiEvaluteCondition as one of the functions that sets the process error record, so I can't use MsiGetLastErrorRecord to see the error text.

I'm running as part of the Execute sequence, after InstallServices, so I'm a lot after CostFinalize.
0 Kudos
Avner_Kashtan
Level 4

I've changed my code. Now instead of a "ManageServices" function that checks Feature state and installs services accordingly, I created several top-level functions ("export prototype"), created an InstallScript Custom Action for each, and used the conditions in the CA.
The very same condition seems to work as part of the sequence, but not inside my InstallScript code. Not going to waste any more time understanding why, it's swallowed way too much time already.
0 Kudos
MichaelU
Level 12 Flexeran
Level 12 Flexeran

Were you trying to run this code from within a deferred custom action? That might explain why otherwise valid condition strings could not be evaluated - if so reading up on and using CustomActionData might be the answer. If you want to debug different condition strings, it shouldn't be hard to write up a loop which prompts you for a condition string, evaluates it, and shows the results; but as you've noticed, the exact execution scheduling may change how it works.
0 Kudos