1

I created a simple WIX project with a "Hello world" custom action and checked how it works. I intended the custom action to be executed only on the first install, but it executed on every major update(where both the product code and its version change). I found in the log that the custom action condition is checked after uninstall - when the Installed variable is false again.

How do I execute a custom action on the first install only and not on major updates, using the WIX toolset? Is there a way without manual use of the registry?

<Product Id="52D5F5ED0C3F453CA70E280ECD7D7400"
         Name="TestWiXSetup"
         Language="1033"
         Version="1.0.2.0"
         Manufacturer="Some RnD"
         UpgradeCode="12777105-8bc1-47b5-8b36-2705ef02cb79">
  <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

  <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
  <MediaTemplate EmbedCab='yes' />

  <Feature Id="ProductFeature" Title="TestWiXSetup" Level="1">
    <ComponentRef Id="Component" />
  </Feature>
  <Binary Id="HW" SourceFile="HW.exe" />
  <CustomAction Id="HWA" BinaryKey="HW" ExeCommand="" Execute='deferred'/>
  <InstallExecuteSequence>
    <Custom Action='HWA' After='InstallFinalize'>NOT Installed</Custom>
  </InstallExecuteSequence>
</Product>

<Fragment>
  <Directory Id="TARGETDIR" Name="SourceDir">
    <Directory Id="ProgramFilesFolder">
      <Directory Id="INSTALLFOLDER" Name="TestWiXSetup">
        <Component Id="Component">
          <File Source="ToDeploy.txt"/>
        </Component>
      </Directory>
    </Directory>
  </Directory>
</Fragment>
George Lanetz
  • 300
  • 5
  • 18
  • 1
    I wonder why would you need such custom action? When Windows Installer do a major upgrade it uninstalls a package completely so no traces are left in the system about its installation status. You could try to trick this by creating a registry value which will not be removed on uninstall and then check it upon the installation. But in this case you'll need a some way to tell the installer about a final uninstallation so it will remove this value. – montonero Feb 27 '19 at 12:40
  • Thank you for clarifying this. I didn't realize any of it when I created the question. – George Lanetz Feb 27 '19 at 12:54
  • 1
    Added a comment to answer below by accident. Please check it out, all I have time for right now is to lob some links your way. Conditions and custom actions are complicated. The basic thing is that the InstallExecuteSequence is run twice (immediate & deferred), and during a major upgrade the uninstall sequence of the **old** (already installed) setup runs, and then the properly conditioned custom actions in the **new** setup being installed. The order can be mixed of what happens first (the uninstall or the fresh install). This depends on the positioning of RemoveExistingProducts. Check links? – Stein Åsmul Feb 27 '19 at 15:52

0 Answers0