“Hide” Features Based on ALLUSERS / MSIINSTALLPERU

2020-04-29 01:55发布

问题:

I have an installer that I'm converting from being an admin-only installation into a Single Package Authoring installer capable of being installed for the current user or for all users. Two of my features require writing to a registry key that would not be available to a regular user. They deal with integration to another application, so I can't write the registry values somewhere else in user space... They have to go in this location.

I'm not concerned with users not being able to install these 2 specific features if they aren't administrators and the installer functions without issue if they aren't selected, but I want to not show them in the feature tree at all and ensure they aren't included in a "Complete" install.

The solutions I've seen let me put conditions around components so the components wouldn't be installed... or to put a condition inside the feature that would set it's level to some high value. How can I disable and/or hide the feature entirely if ALLUSERS=2 or MSIINSTALLPERUSER=1.

回答1:

Per-User Setups: I won't lie to you, I actively avoid this sort of setup. I find MSI's per-user installation constructs "not ideal". It relates to poor serviceability (upgrades, patching, etc...) and a number of other details. Some details mid-page here.

Some links for others who read this answer (I think you have read these):

  • Nice summary page on single package authoring from Advanced Installer
  • Single Package Authoring
  • Installation context
  • MSIINSTALLPERUSER

Feature Conditions: With that said you can use feature conditions to unselect features based on whether a certain condition is true or false. You can even set the Level of a feature to 0 which will hide it from the GUI entirely during installation. You could try this. Please also read the linked answer below (bolded). It contains a better explanation of feature conditions.

I don't have time to test this, but here is a WiX mock-up that you can try:

<Feature Id="MyFeature" Level="1"> <!--Default to install feature-->

    <Condition Level="0"> <!--Do not install feature if condition is true-->
       ALLUSERS=2 OR MSIINSTALLPERUSER=1
    </Condition>

</Feature>

These answers might help you get an overview of this:

  • How to set the level of feature based on condition in wix? (please do read this one).

  • InstallShield conditional feature installation

  • Failing condition wix


Hide Feature Testing: I will add a little snippet you can use to verify the operation of the feature hiding. It forces the condition in question to be true by setting it to 1 - as opposed to using a "real condition" that can be false unexpectedly.

<Feature Id="SupportingFiles" Title="SupportingFiles" Level="1">
   <Condition Level="0">1</Condition>
</Feature>

This should hide the SupportingFiles feature from view in the setup GUI, and it should also not install it. Please let me know if you see a different behavior.


Custom Actions: To interactively hide a feature based on changes done in the GUI, you can try to use custom actions to control the feature levels.

  • Unselected Feature Being Installed

I am not sure this will work. I will test when I get the chance. Just adding that link for now.

UPDATE: I am unable to investigate this right now. I want to alert you to the possibility of adding temporary rows to the database during installation. Perhaps this is the way to go to hide the feature "interactively". I just don't know since I have never tried. Here is the first link I found on temporary records. And towards the bottom here are links. No guarantees.

Other than that I suppose you could use an external GUI launcher. I might comment on this later. I recently wrote about this issue (external GUI).


Some Further Links For Reference:

  • How to set the level of feature based on condition in wix?
  • Unselected Feature Being Installed
  • WiX Checkbox property only working if default value given