Why "and NOT installed" when running an app after install with Wix?
Asked Answered
F

3

5

On the Wix's document How To: Run the Installed Application After Setup, the condition for the Publish element contains and NOT Installed aside from the property that contains whether the application should be run or not:

<Publish Dialog="ExitDialog"
         Control="Finish" 
         Event="DoAction" 
         Value="LaunchApplication">WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1 and NOT Installed</Publish>

Why is it there? What does it do?

Freighter answered 12/4, 2018 at 15:44 Comment(0)
D
6

The custom action pointed to by the Publish element will run only when the whole condition provided evaluates to true.

  • NOT Installed: is true for fresh installation and major upgrade. Otherwise always false.
  • WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1: is true when the property is set equal to 1.

So, translating the condition into words: launch the application on fresh install and major upgrade install only when WIXUI_EXITDIALOGOPTIONALCHECKBOX is also set to 1. Otherwise do not launch. Both conditions must be satisfied for launch to happen.

Technically: Installed is essentially checking whether the product GUID of the MSI you are installing is already registered as installed on the system. If it is, then the condition NOT Installed evaluates to true.


Launching Application: Yes, this can be a bit confusing, but it does what it says in the documentation: it makes the application only launch during fresh install and not during repair, modify, uninstall, minor upgrade patch (or other installation modes).

Interestingly it should (as far as I can see) cause the application to launch during an interactive major upgrade as well (Installed is not true for the new setup being installed on top of the old one, but it is true for the uninstalling setup - a major upgrade is essentially and uninstall of the old version and a fresh install of the new version).

So NOT Installed seems to only be true in two cases: fresh install and major upgrade. The two cases where you want to auto-magically launch your application?

Since the InstallUISequence is skipped in silent installation mode, there will be no application launched after a silent install since your dialog will never be encountered (only the InstallExecuteSequence runs).


Digression, similar issue - LaunchCondition: I just commented on almost the same issue the other day in the context of LaunchConditions. If you follow the link, please be sure to read Phil's follow-up comment as well.

To use other words than above: essentially the OR'd Installed condition ensures that the LaunchCondition only applies on fresh installation (or on major upgrade for the new package being installed on top of the old one). This seems to be a nifty feature from the WiX guys - I noticed Installshield does not seem to use this concept. I haven't tested this much, but it seems like a good concept.

Alternatively, as Phil states in the linked comment above, in the context of LaunchConditions you could condition the LaunchConditions actions instead of complicating the actual LaunchConditon condition. Not sure which is better.


UPDATE:

On Conditions In General: MSI conditions can be quite confusing. Here are some resources to work them out:

I have one further link that I tend to provide, but it has a number of subtle problems that I want to test out before sending people to the content.

Darnell answered 12/4, 2018 at 19:30 Comment(0)
F
0

It probably isn't clear from a (seemingly casual) condition such as "not Installed", but there is a set of standard Windows Installer properties, and Installed is one of them:

https://msdn.microsoft.com/en-us/library/windows/desktop/aa370905(v=vs.85).aspx

A product is "installed" if its ProductCode is registered as installed on the system. In the context of that WiX source, it means "run only when the product is not already installed".

Conditions are especially important in custom actions. If you don't put any conditions on a custom action then it will run at install time, and also whenever and install-type operation takes place, such as uninstall, repair, applying s patch. Conditions are documented here:

https://msdn.microsoft.com/en-us/library/aa368012(v=vs.85).aspx

Fung answered 12/4, 2018 at 19:58 Comment(0)
H
0

The Not Installed condition attempts to ensure that even if WIXUI_EXITDIALOGOPTIONALCHECKBOX is set to 1 by default, the action is only published in scenarios that the exe is strongly likely to be present. Why do this? If someone selects to launch the exe when it's not present, an error message, or a missing UI, could confuse the user. In other parts of the installation process, a failed launch could abort and roll back the installer.

By then why is the condition NOT Installed? That probably sounds backwards to you. But it's not an accident. The Installed property is set at the launch of your installer, and is not updated until the next time it is launched. Even when the installer alters the state by installing or uninstalling the product, the value of Installed is left untouched.

So what are the scenarios where NOT Installed will be true on the ExitDialog?

First-time install: Installed will start (and remain) false, so at the end NOT Installed will be true. If the installation completes successfully, your exe is probably there. If the installation is cancelled or rolls back, the installer could show a different final dialog that does not offer the launch option.

Maintenance, repair, uninstallation: Installed will start as true, so at completion NOT Installed will be false. This can result in a false negative in, e.g., a repair scenario; the exe may be present but the installer will not try to launch it. But, more importantly, it prevents the attempt to launch the exe after it was just uninstalled.

Upgrades: Depending on the type of upgrade, this will be equivalent to one of the prior scenarios. Minor upgrades and small updates are a form of maintenance, whereas major upgrades act like a first-time install.

Note that this condition may not be foolproof in more complex projects. If your exe is installed only in a subset of your configurations (e.g., if it's installed only by a feature that you can choose to exclude, or by a component that depends on the version of the OS), you may want to enhance the condition or remove the launch action entirely.

I say could show a different dialog because I'm uncertain what WixUI_Minimal does here. If it shows the same dialog, then the condition is insufficient to accomplish what I described here.

Horacehoracio answered 13/4, 2018 at 13:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.