2

I'm making installer with WiX 3.10. My original task is to copy Postgres files to target system, initialize cluster, register service, start it and restore database on install, and in reverse - stop service, remove it from system, and clear up cluster data. I wrote two bat files, and added custom actions to execute them and some conditions as described in various places, but none of them working. I've tried with and without CDATA, Installed, INSTALLED and some other variations, but it always executes both actions.

Here is the wix file I'm experimenting with now.

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Id="*" Name="Hatred_6" Language="1033" Version="1.0.0.0" Manufacturer="Satan" UpgradeCode="d9602b10-8428-4031-8c82-99288b21377f">
        <Package InstallerVersion="405" Compressed="yes" InstallScope="perMachine"  InstallPrivileges="elevated"/>

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

        <CustomAction Id="AAction" Directory="INSTALLFOLDER" Execute="deferred" Impersonate="no" Return="check"
                      ExeCommand="cmd.exe /c &quot;a.bat&quot;">NOT Installed</CustomAction>

        <CustomAction Id="BAction" Directory="INSTALLFOLDER" Execute="deferred" Impersonate="no" Return="check"
                      ExeCommand="cmd.exe /c &quot;b.bat&quot;">Installed</CustomAction>

        <InstallExecuteSequence>
            <Custom Action="BAction" After="InstallFiles" />
            <Custom Action="AAction" After="InstallFiles" />
        </InstallExecuteSequence>

        <Feature Id="ProductFeature" Title="Hatred_6" Level="1">
            <ComponentGroupRef Id="ProductComponents" />
        </Feature>
    </Product>

    <Fragment>
        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="ProgramFilesFolder">
                <Directory Id="INSTALLFOLDER" Name="Hatred_6" />
            </Directory>
        </Directory>
    </Fragment>

    <Fragment>
        <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
            <Component Id="CalcComponent" Guid="515C0606-FD73-4B5D-ACF4-481123092A3E">
                <File Id="CalcFile" KeyPath="yes" Source="calc.exe" />
            </Component>
            <Component Id="AComponent" Guid="515e3aa0-e5a0-4cd1-aaa5-ebf25a679a24">
                <File Id="AFile" KeyPath="yes" Source="a.bat" />
            </Component>
            <Component Id="BComponent" Guid="85f7627e-fc39-4f78-a870-221d2d08375d">
                <File Id="BFile" KeyPath="yes" Source="b.bat" />
            </Component>
        </ComponentGroup>
    </Fragment>
</Wix>

bat files contain dir > a.txt and dir > b.txt so I can see if they actually executed. It's somewhat frustrating, am I misunderstanding something?

Encarmine
  • 453
  • 3
  • 13
  • I would suggest using a verbose log rather than `dir > a.txt` to determine if a custom action executes. – Michael Urman Sep 10 '16 at 14:58
  • I need both bat files to produce side-effects anyway, and I didn't find anything in verbose log that can explain how action's conditions evaluated. – Encarmine Sep 11 '16 at 07:42

1 Answers1

8

Condition should be placed inside Custom element, not CustomAction. Also, you have no InstallFiles action during uninstalling. Use RemoveFiles instead.

<CustomAction Id="AAction" Directory="INSTALLFOLDER" Execute="deferred" 
              Impersonate="no" Return="check" ExeCommand="cmd.exe /c &quot;a.bat&quot;" />
<CustomAction Id="BAction" Directory="INSTALLFOLDER" Execute="deferred"
              Impersonate="no" Return="check" ExeCommand="cmd.exe /c &quot;b.bat&quot;" />

<InstallExecuteSequence>
    <Custom Action="AAction" After="InstallFiles">NOT Installed</Custom>
    <Custom Action="BAction" Before="RemoveFiles">Installed</Custom>
</InstallExecuteSequence>
Anton Sutarmin
  • 807
  • 8
  • 15
  • These conditions will still run during upgrades. "Installed" refers to the {Product GUID} product being installed. With major upgrades, the product GUID is different but the Upgrade GUIDs match so we know which product this is an upgrade of. I would amend the two conditions to `NOT WIX_UPGRADE_DETECTED AND NOT Installed)` and `NOT UPGRADINGPRODUCTCODE AND REMOVE~="ALL"` to get these actions to run **only** on first installs and complete uninstalls. – Brian Sutherland Sep 12 '16 at 14:54
  • @BrianSutherland, you are right, but experience shows that services should be stopped during major upgrades, so for authors purpose original conditions are better. – Anton Sutarmin Sep 12 '16 at 15:13
  • @SutarminAnton The error I made is kinda embarrassing, Your suggestion helped. As for exact conditions I need - there are some good cheatsheets on other SO answers like this http://stackoverflow.com/questions/320921/how-to-add-a-wix-custom-action-that-happens-only-on-uninstall-via-msi – Encarmine Sep 12 '16 at 20:02