How to change RemoveExistingProducts to after InstallFinalize when using WixUI_Advanced? - wix

Here's my scenario:
Using Wix 3.6
Using the WixUI_Advanced dialog set (adds ability able to control individual features during install)
Setting NeverOverwrite="yes" for a web.config component (so that local changes post-install aren't lost)
However, the installer still seems to remove and re-install the web.config file during upgrade.
Best I can tell the WixUI_Advanced dialog set has something like the following configured:
<InstallExecuteSequence>
<RemoveExistingProducts After="InstallInitialize"/>
</InstallExecuteSequence>
Here are logs snippets from the install:
MSI (s) (74:8C) [18:37:00:959]: Executing op: ActionStart(Name=InstallInitialize,,)
Action 18:37:00: InstallInitialize.
...
Action 18:37:00: ProcessComponents. Updating component registration
...
Action 18:37:00: UnpublishFeatures. Unpublishing Product Features
...
UnpublishFeatures: Feature: ProductFeature
...
UnpublishFeatures: Feature: AdditionalFeature
...
MSI (s) (74:8C) [18:37:00:967]: Executing op: ActionStart(Name=RemoveFiles,Description=Removing files,Template=File: [1], Directory: [9])
Action 18:37:00: RemoveFiles. Removing files
MSI (s) (74:8C) [18:37:00:967]: Executing op: ProgressTotal(Total=2,Type=1,ByteEquivalent=175000)
MSI (s) (74:8C) [18:37:00:967]: Executing op: SetTargetFolder(Folder=C:\Program Files (x86)\MyTestApp\WebApp\)
MSI (s) (74:8C) [18:37:00:967]: Executing op: FileRemove(,FileName=web.config,,ComponentId={B4A12A8F-56A3-4DD1-A0BA-B9C39EB305FD})
RemoveFiles: File: web.config, Directory: C:\Program Files (x86)\MyTestApp\WebApp\
MSI (s) (74:8C) [18:37:00:968]: Verifying accessibility of file: web.config
MSI (s) (74:8C) [18:37:00:969]: Note: 1: 2318 2:
MSI (s) (74:8C) [18:37:00:969]: Note: 1: 2318 2:
MSI (s) (74:8C) [18:37:00:969]: Executing op: FileRemove(,FileName=somefile.txt,,ComponentId={B835CEF5-1A84-4C37-8CB0-BE983BAF73F9})
RemoveFiles: File: somefile.txt, Directory: C:\Program Files (x86)\MyTestApp\WebApp\
MSI (s) (74:8C) [18:37:00:970]: Verifying accessibility of file: somefile.txt
MSI (s) (74:8C) [18:37:00:970]: Note: 1: 2318 2:
MSI (s) (74:8C) [18:37:00:970]: Note: 1: 2318 2:
MSI (s) (74:8C) [18:37:00:971]: Executing op: ActionStart(Name=PublishProduct,Description=Publishing product information,)
Action 18:37:00: PublishProduct. Publishing product information
...
Action 18:37:00: RollbackCleanup. Removing backup files
RollbackCleanup: File: C:\Config.Msi\7cd65c.rbf
RollbackCleanup: File: C:\Config.Msi\7cd65d.rbf
MSI (s) (74:8C) [18:37:00:980]: Note: 1: 2318 2:
MSI (s) (74:8C) [18:37:00:981]: Note: 1: 2318 2:
MSI (s) (74:8C) [18:37:00:981]: No System Restore sequence number for this installation.
MSI (s) (74:8C) [18:37:00:981]: Unlocking Server
MSI (s) (74:8C) [18:37:00:985]: PROPERTY CHANGE: Deleting UpdateStarted property. Its current value is '1'.
Action ended 18:37:00: InstallFinalize. Return value 1.
Action ended 18:37:00: INSTALL. Return value 1.
As you can see it removes the web.config file after InstallInitialize
When I try to change the wxs file, adding:
<InstallExecuteSequence>
<RemoveExistingProducts After="InstallFinalize"/>
</InstallExecuteSequence>
I get:
error LGHT0091: Duplicate symbol 'WixAction:InstallExecuteSequence/RemoveExistingProducts' found. This typically means that an Id is duplicated. Check to make sure all your identifiers of a given type (File, Component, Feature) are unique.
Here is the Product.wxs file I'm using:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
<Product Id="*" Name="MyTestInstaller" Language="1033" Version="1.0.9.0" Manufacturer="Acme, Inc" UpgradeCode="6ca3779c-e8ce-42e8-bf81-3166bd96e585">
<Package Id="*" InstallerVersion="301" Compressed="yes" InstallScope="perMachine" Platform="x64" InstallPrivileges="elevated" />
<Upgrade Id="6ca3779c-e8ce-42e8-bf81-3166bd96e585">
<UpgradeVersion Minimum="1.0.9.0" OnlyDetect="yes" Property="NEWERVERSIONDETECTED" />
<UpgradeVersion OnlyDetect="no" Minimum="0.0.0.0" IncludeMinimum="yes" Maximum="1.0.9.0" Property="OLDERVERSIONBEINGUPGRADED" IgnoreRemoveFailure="yes">
</UpgradeVersion>
</Upgrade>
<Condition Message="A later version of [ProductName] is already installed.">NOT NEWERVERSIONDETECTED</Condition>
<Media Id="1" Cabinet="myapp.cab" EmbedCab="yes" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<Feature Id="ProductFeature" Title="MyTestInstaller" Level="1">
<ComponentGroupRef Id="ProductComponents" />
</Feature>
<Feature Id="AdditionalFeature" Title="Additional Features" Level="10">
<ComponentGroupRef Id="AdditionalComponents"/>
</Feature>
<Property Id="ApplicationFolderName" Value="MyTestApp"/>
<!-- BEGIN: DISABLE THE Per User Install -->
<Property Id="WixAppFolder" Value="WixPerMachineFolder"/>
<WixVariable Id="WixUISupportPerUser" Value="0" />
<!-- END: DISABLE THE Per User Install -->
<UI>
<UIRef Id="WixUI_Advanced" />
</UI>
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="APPLICATIONFOLDER" Name="ICS">
<Directory Id="WebApp" Name="WebApp">
<Component Id="WEB.CONFIG" Guid="B4A12A8F-56A3-4DD1-A0BA-B9C39EB305FD" DiskId="1" NeverOverwrite="yes">
<File Id="WEB.CONFIG" Name="web.config" Source="web.config" KeyPath="yes"/>
</Component>
<Component Id="SOMEFILE" DiskId="1" Guid="B835CEF5-1A84-4C37-8CB0-BE983BAF73F9">
<File Id="SOMEFILE" Name="somefile.txt" Source="somefile.txt" KeyPath="yes"/>
<util:XmlConfig Id="WEBCFG_1" File="[WebApp]Web.config" Action="create" Node="element" Name="module" ElementPath="/configuration/autofac/modules" VerifyPath="/configuration/autofac/modules/module[\[]#type='ICS.Automation.JDE.Base.JDEModule, ICS.Automation.JDE.Base'[\]]" Sequence="10" On ="install" />
<util:XmlConfig Id="WEBCFG_2" ElementId="WEBCFG_1" File="[WebApp]Web.config" Name="type" Value="MyDll, MyDll" Sequence="11" />
</Component>
</Directory>
</Directory>
</Directory>
</Directory>
</Fragment>
<Fragment>
<ComponentGroup Id="ProductComponents">
<ComponentRef Id="WEB.CONFIG"/>
</ComponentGroup>
<ComponentGroup Id="AdditionalComponents">
<ComponentRef Id="SOMEFILE"/>
</ComponentGroup>
</Fragment>
</Wix>
How can I change the RemoveExistingProducts to come after InstallFinalize?
Ultimately, I just need this file to never be overwritten.
Thanks!

The MajorUpgrade tag is the preferred way to do the upgrade, and that will sequence RemoveExistingProducts (REP) wherever you specify - that should simplify some of this. There's no reason for the UI to move REP around.
The default for scheduling REP is after InstallValidate, which is basically a uninstall of the old product followed by an install of the upgrade, so it's not so much an update/overwrite of the config file as an uninstall/remove followed by a fresh install.
If the REP is scheduled afterInstallExecute then overwrite rules apply during the upgrade (because the upgrade "overwrites" the existing installed product before it's uninstalled). The web.config file just needs to have the same component id in both the old and new products, and if it has indeed been changed after it was installed then the overwrite rules should mean it won't be overwritten.
https://msdn.microsoft.com/en-us/library/windows/desktop/aa370531(v=vs.85).aspx
In other words just use the major upgrade element with afterInstallExecute, have the same component ids in both old and new resources (files etc) and the web.config file shouldn't be overwritten, and you don't need to set neveroverwrite.
In my opinion having REP afterInstallExecute is better than after InstallFinalize because the latter is outside the install transaction, so the upgrade install can succeed, then the REP after InstallFinalize can fail and roll back, leaving both products simultaneously installed. Having REP within the transaction results in a full rollback if the uninstall of the older product fails.

Related

WiX toolset - EventSource sets wrong path to EventMessageFile (prepends "#%")

I have WiX 4.0 project. I'm using Util to create Windows EventLog event source. The problem is, the Registry entry to the EventMessageFile gets the path prepended with "#%". Therefore, the EventLog will display errors for events created by this event source.
Code to create the EventSource:
<Include xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:util="http://wixtoolset.org/schemas/v4/wxs/util">
<PropertyRef Id="NETFRAMEWORK40FULLINSTALLROOTDIR64"/>
<PropertyRef Id="NETFRAMEWORK40CLIENTINSTALLROOTDIR64"/>
<PropertyRef Id="NETFRAMEWORK40CLIENT"/>
<PropertyRef Id="NETFRAMEWORK40FULL"/>
.
.
.
<ComponentGroup Id="EventLog" Directory="INSTALLFOLDER">
<!-- 64 bit -->
<Component Id="CreateEventSource64BitFullNet4" DiskId="1" Guid="{9978592B-3E96-4AAA-B7A6-34B0421FDD02}" Condition="NETFRAMEWORK40FULLINSTALLROOTDIR64 AND VersionNT64">
<CreateFolder/>
<util:EventSource Log="Application" Name="ScholarshipSapQueue" EventMessageFile="[NETFRAMEWORK40FULLINSTALLROOTDIR64]EventLogMessages.dll" />
</Component>
<Component Id="CreateEventSource64BitClientNet4" DiskId="1" Guid="{B42622A1-B7C0-48CB-B306-65F3558C6678}" Condition="NETFRAMEWORK40CLIENTINSTALLROOTDIR64 AND NOT NETFRAMEWORK40FULL AND VersionNT64">
<CreateFolder/>
<util:EventSource Log="Application" Name="ScholarshipSapQueue" EventMessageFile="[NETFRAMEWORK40CLIENTINSTALLROOTDIR64]EventLogMessages.dll" />
</Component>
</ComponentGroup>
</Include>
Looking at the log file from installing the MSI, the value of the properties does look correct:
MSI (c) (B4:68) [10:05:27:331]: PROPERTY CHANGE: Adding NETFRAMEWORK40FULLINSTALLROOTDIR64 property. Its value is 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\'.
But the Registry entry is wrong:
MSI (s) (3C:28) [10:05:33:008]: Executing op: ActionStart(Name=WriteRegistryValues,Description=Writing system registry values,Template=Key: [1], Name: [2], Value: [3])
Action 10:05:33: WriteRegistryValues. Writing system registry values
MSI (s) (3C:28) [10:05:33:014]: Executing op: ProgressTotal(Total=1,Type=1,ByteEquivalent=13200)
MSI (s) (3C:28) [10:05:33:014]: Executing op: RegOpenKey(Root=-2147483646,Key=SYSTEM\CurrentControlSet\Services\EventLog\Application\ScholarshipSapQueue,,BinaryType=0,,)
MSI (s) (3C:28) [10:05:33:014]: Executing op: RegAddValue(Name=EventMessageFile,Value=##%C:\Windows\Microsoft.NET\Framework64\v4.0.30319\EventLogMessages.dll,)
WriteRegistryValues: Key: \SYSTEM\CurrentControlSet\Services\EventLog\Application\ScholarshipSapQueue, Name: EventMessageFile, Value: ##%C:\Windows\Microsoft.NET\Framework64\v4.0.30319\EventLogMessages.dll
That smells like a WiX v4 bug. Please open an issue at https://github.com/wixtoolset/issues/issues/new/choose.

wixtoolset: Component condition is not evaluating as expected on changing MajorUpgrade schedule to afterInstallInitialize

MajorUpgrade element is scheduled after install finalize in our product's MSI:
<MajorUpgrade Schedule="afterInstallFinalize" AllowSameVersionUpgrades="yes" DowngradeErrorMessage="!(loc.NewerVersionInstalled)" IgnoreRemoveFailure="no"/>
There are some folders written by app at runtime that we want to keep on upgrade and only remove on uninstall initiated from Add/Remove programs. So we use this condition: (NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL").
<DirectoryRef Id="TARGETDIR">
...
<Directory Id="LocalAppDataFolder"
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
<Component Id="CreatePrivateMyAppFolder" Guid="FA1F4375-71DA-4E61-9A02-BE7FD2D4C87D">
<RegistryValue Root="HKCU" Key="Software\Company\Product" Name="PrivateFolderMyApp" Type="string" Value="[PrivateDataMyApp]" KeyPath="yes"/>
</Component>
<Component Id="RemoveLocalAppDataMyAppUninstall" Guid="*" Transitive="yes">
<Condition><![CDATA[(NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")]]></Condition>
<RegistryValue Root="HKCU" Key="Software\Company\Product" Name="PrivateFolderMyApp" Type="string" Value="[PrivateDataMyApp]" KeyPath="yes"/>
<util:RemoveFolderEx On="uninstall" Property="PRIVATEMYAPPFOLDER"/>
</Component>
<Directory></Directory>
...
</Directory>
</DirectoryRef>
I need to change the MajorUpgrade schedule from afterInstallFinalize to afterInstallInitialize for some new requirements. I install version 1 with new schedule. Then install versions 2. However during uninstall sequence of version 2, folders written by runtime are being removed.
From logs, both UPGRADINGPRODUCTCODE and REMOVE properties are set for the uninstall part. Based on that the condition (NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL") should evaluate to false for the component RemoveLocalAppDataMyAppUninstall.
MSI (s) (C4:58) [22:58:11:060]: Doing action: RemoveExistingProducts
Action 22:58:11: RemoveExistingProducts. Removing applications
Action start 22:58:11: RemoveExistingProducts.
RemoveExistingProducts: Application: {8F890AE0-BE0A-5ED9-B406-F7459B3390F9}, Command line: UPGRADINGPRODUCTCODE={70705091-36C8-5619-9E35-73E455CA17F7} CLIENTPROCESSID=4756 CLIENTUILEVEL=0 REMOVE=ALL
....
MSI (s) (C4:4C) [22:58:11:076]: Command Line: UPGRADINGPRODUCTCODE={70705091-36C8-5619-9E35-73E455CA17F7} CLIENTPROCESSID=4756 CLIENTUILEVEL=0 REMOVE=ALL
MSI (s) (C4:4C) [22:58:11:279]: Dir (target): Key: _PRIVATEMYAPPFOLDER_4 , Object: C:\Users\Windows_10\AppData\Local\MyApp\
MSI (s) (C4:4C) [22:58:11:279]: Dir (target): Key: _PRIVATEMYAPPFOLDER_3 , Object: C:\Users\Windows_10\AppData\Local\MyApp\1753de9b-15a7-49b1-8715-f93a967d12e5\
...
MSI (s) (C4:4C) [22:58:11:826]: Doing action: InstallValidate
MSI (s) (C4:4C) [22:58:11:826]: Component: RemoveLocalAppDataMyAppUninstall; Installed: Local; Request: Absent; Action: Absent
...
MSI (s) (C4:4C) [22:58:12:732]: Doing action: RemoveFiles
MSI (s) (C4:4C) [22:58:12:919]: Counted 6 foreign folders to be removed.
MSI (s) (C4:4C) [22:58:12:919]: Removing foreign folder: C:\Users\Windows_10\AppData\Local\MyApp\1753de9b-15a7-49b1-8715-f93a967d12e5\
MSI (s) (C4:4C) [22:58:12:919]: Removing foreign folder: C:\Users\Windows_10\AppData\Local\MyApp\
Any help in understanding why the condition is being applied during uninstall will be appreciated.
Component conditions only affect install and, with the transitive bit set, reinstall. Uninstall isn't affected. RemoveFolderEx in WiX v4 has a Condition that lets you do what you want to do.

Installation should be executed twice to install the major upgrade for the application

Major upgrade does not work correctly for following installation.
If the previous version of the application is installed on the current PC, then during major upgrade old version will be automatically uninstalled, but new version is not installed by some reason.
I need to run this new installation twice in order to uninstall the old version and then install new one.
But if I comment out the custom action LaunchApplication in the old version of installation, then there will not be any problems and old version will be uninstalled and new version will be installed during the one run of the new installation.
<?xml version='1.0' encoding='windows-1252'?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Name='Foobar 2.0.0' Id='GUID' UpgradeCode='GUID'
Language='1033' Codepage='1252' Version='2.0.0' Manufacturer='Acme Ltd.'>
<Package Id='*' Keywords='Installer' Description="Acme's Foobar 2.0.0 Installer"
Comments='Foobar is a registered trademark of Acme Ltd.' Manufacturer='Acme Ltd.'
InstallerVersion='100' Languages='1033' Compressed='yes' SummaryCodepage='1252' />
<Property Id="ALLUSERS" Secure="yes" Value="2" />
<Property Id="MSIINSTALLPERUSER" Secure="yes" Value="1" />
<Property Id='ApplicationFolderName' Value="Acme" />
<Property Id='WixAppFolder' Value="WixPerUserFolder" />
<Upgrade Id='GUID'>
<UpgradeVersion OnlyDetect='no' Property='PREVIOUSFOUND'
Minimum='0.0.1' IncludeMinimum='yes'
Maximum='2.0.0' IncludeMaximum='no' />
<UpgradeVersion OnlyDetect='yes' Property='NEWERFOUND'
Minimum='2.0.0' IncludeMinimum='no' />
</Upgrade>
<Media Id='1' Cabinet='Sample.cab' EmbedCab='yes' DiskPrompt="CD-ROM #1" />
<Property Id='DiskPrompt' Value="Acme's Foobar 2.0.0 Installation [1]" />
<Directory Id='TARGETDIR' Name='SourceDir'>
<Directory Id='ProgramFilesFolder' Name='PFiles'>
<Directory Id='Acme' Name='Acme'>
<Directory Id='INSTALLDIR' Name='Foobar 2.0.0'>
</Directory>
</Directory>
</Directory>
</Directory>
<DirectoryRef Id="INSTALLDIR">
<Component Id='start.vbs' Guid='GUID'>
<File Id='start.vbs' Name='start.vbs' DiskId='1' Source='start.vbs' KeyPath='yes' >
</File>
</Component>
</DirectoryRef>
<Feature Id='Complete' Title='Foobar 2.0.0' Description='The complete package.'
Display='expand' Level='1' ConfigurableDirectory='INSTALLDIR'>
<Feature Id='MainProgram' Title='Program' Description='The main executable.' Level='1'>
<ComponentRef Id='start.vbs' />
</Feature>
</Feature>
<CustomAction Id='AlreadyUpdated' Error='[ProductName] has already been updated to 2.0.0 or newer.' />
<CustomAction Id='NoDowngrade' Error='A later version of [ProductName] is already installed.' />
<Property Id="WixShellExecTarget" Value="[#start.vbs]" />
<CustomAction Id="LaunchApplication"
BinaryKey="WixCA"
DllEntry="WixShellExec"
Execute="immediate"
Impersonate="yes" />
<InstallExecuteSequence>
<Custom Action='AlreadyUpdated' After='FindRelatedProducts'>SELFFOUND</Custom>
<Custom Action="NoDowngrade" After="FindRelatedProducts">NEWERFOUND</Custom>
<RemoveExistingProducts Before="InstallInitialize" />
<Custom Action="LaunchApplication" After="InstallFinalize"/>
</InstallExecuteSequence>
</Product>
</Wix>
What could be wrong with this installation or with custom action?
VBS procedure is empty.
start.vbs:
Private Function startServerSub()
End Function
startServerSub
What should be changed to have ability to uninstall previous version and install new one during one run of new application?
UPDATE:
I changed my installation a little.
1. RemoveExistingProducts will be executed after InstallInitialize.
2. Added SELFFOUND to Upgrade element.
<?xml version='1.0' encoding='windows-1252'?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Name='TestApp 2.0.0' Id='GUID' UpgradeCode='GUID'
Language='1033' Codepage='1252' Version='2.0.0' Manufacturer='TestManufacturer Ltd.'>
<Package Id='*' Keywords='Installer' Description="TestManufacturer's TestApp 2.0.0 Installer"
Comments='TestAppis a registered trademark of TestManufacturer Ltd.' Manufacturer='TestManufacturer Ltd.'
InstallerVersion='100' Languages='1033' Compressed='yes' SummaryCodepage='1252' />
<Property Id="ALLUSERS" Secure="yes" Value="2" />
<Property Id="MSIINSTALLPERUSER" Secure="yes" Value="1" />
<Property Id='ApplicationFolderName' Value="TestManufacturer" />
<Property Id='WixAppFolder' Value="WixPerUserFolder" />
<Upgrade Id='GUID'>
<UpgradeVersion OnlyDetect='yes' Property='SELFFOUND'
Minimum='2.0.0' IncludeMinimum='yes'
Maximum='2.0.0' IncludeMaximum='yes' />
<UpgradeVersion OnlyDetect='no' Property='PREVIOUSFOUND'
Minimum='0.0.1' IncludeMinimum='yes'
Maximum='2.0.0' IncludeMaximum='no' />
<UpgradeVersion OnlyDetect='yes' Property='NEWERFOUND'
Minimum='2.0.0' IncludeMinimum='no' />
</Upgrade>
<Media Id='1' Cabinet='Sample.cab' EmbedCab='yes' DiskPrompt="CD-ROM #1" />
<Property Id='DiskPrompt' Value="TestManufacturer's TestApp 2.0.0 Installation [1]" />
<Directory Id='TARGETDIR' Name='SourceDir'>
<Directory Id='ProgramFilesFolder' Name='PFiles'>
<Directory Id='TestManufacturer' Name='TestManufacturer'>
<Directory Id='INSTALLDIR' Name='TestApp 2.0.0'>
</Directory>
</Directory>
</Directory>
</Directory>
<DirectoryRef Id="INSTALLDIR">
<Component Id='start.vbs' Guid='GUID'>
<File Id='start.vbs' Name='start.vbs' DiskId='1' Source='start.vbs' KeyPath='yes' >
</File>
</Component>
</DirectoryRef>
<Feature Id='Complete' Title='TestApp 2.0.0' Description='The complete package.'
Display='expand' Level='1' ConfigurableDirectory='INSTALLDIR'>
<Feature Id='MainProgram' Title='Program' Description='The main executable.' Level='1'>
<ComponentRef Id='start.vbs' />
</Feature>
</Feature>
<CustomAction Id='AlreadyUpdated' Error='[ProductName] has already been updated to 2.0.0 or newer.' />
<CustomAction Id='NoDowngrade' Error='A later version of [ProductName] is already installed.' />
<Property Id="WixShellExecTarget" Value="[#start.vbs]" />
<CustomAction Id="LaunchApplication"
BinaryKey="WixCA"
DllEntry="WixShellExec"
Execute="immediate"
Impersonate="yes" />
<InstallExecuteSequence>
<Custom Action='AlreadyUpdated' After='FindRelatedProducts'>SELFFOUND</Custom>
<Custom Action="NoDowngrade" After="FindRelatedProducts">NEWERFOUND</Custom>
<RemoveExistingProducts After="InstallInitialize" />
<Custom Action="LaunchApplication" After="InstallFinalize"/>
</InstallExecuteSequence>
</Product>
</Wix>
Then I created 4 installation packages:
1. Version 1.0.0 with custom action LaunchApplication after InstallFinalize.
2. Version 1.0.0 without custom action LaunchApplication.
3. Version 2.0.0 with custom action LaunchApplication after InstallFinalize.
4. Version 2.0.0 without custom action LaunchApplication.
It is impossible to install any type of version 2.0.0, if version 1.0.0 with custom action was installed.
I tried to install version 2.0.0(without custom action) after version 1.0.0(with custom action):
=== Verbose logging started: 7/22/2015 18:37:48 Build type: SHIP UNICODE 5.00.7601.00 Calling process: C:\Windows\system32\msiexec.EXE ===
...
Action 18:37:48: FindRelatedProducts. Searching for related applications
Action start 18:37:48: FindRelatedProducts.
FindRelatedProducts: Found application: {GUID of 1.0.0}
MSI (c) (A8:A4) [18:37:48:221]: PROPERTY CHANGE: Adding PREVIOUSFOUND property. Its value is '{GUID of 1.0.0}'.
...
Action start 18:37:48: InstallInitialize.
MSI (s) (F4:0C) [18:37:48:299]: Machine policy value 'AlwaysInstallElevated' is 0
MSI (s) (F4:0C) [18:37:48:299]: User policy value 'AlwaysInstallElevated' is 0
MSI (s) (F4:0C) [18:37:48:299]: BeginTransaction: Locking Server
MSI (s) (F4:0C) [18:37:48:299]: Note: 1: 1715 2: TestApp 2.0.0
MSI (s) (F4:0C) [18:37:48:299]: Note: 1: 2262 2: Error 3: -2147287038
MSI (s) (F4:0C) [18:37:48:299]: Calling SRSetRestorePoint API. dwRestorePtType: 0, dwEventType: 102, llSequenceNumber: 0, szDescription: "Installed TestApp 2.0.0".
MSI (s) (F4:0C) [18:37:48:299]: The System Restore service is disabled. Returned status: 1058. GetLastError() returned: 1058
MSI (s) (F4:0C) [18:37:48:299]: Server not locked: locking for product {GUID of 2.0.0}
Action ended 18:37:48: InstallInitialize. Return value 1.
MSI (s) (F4:0C) [18:37:48:845]: Doing action: RemoveExistingProducts
MSI (s) (F4:0C) [18:37:48:845]: Note: 1: 2205 2: 3: ActionText
Action start 18:37:48: RemoveExistingProducts.
MSI (s) (F4:0C) [18:37:48:845]: Note: 1: 2262 2: Error 3: -2147287038
MSI (s) (F4:0C) [18:37:48:845]: Note: 1: 2262 2: Error 3: -2147287038
...
Action start 18:37:48: InstallFinalize.
...
MSI (s) (F4:AC) [18:37:48:939]: Verifying accessibility of file: start.vbs
MSI (s) (F4:AC) [18:37:48:939]: Note: 1: 2318 2:
MSI (s) (F4:AC) [18:37:48:939]: Note: 1: 2318 2:
...
Action ended 18:37:48: InstallFinalize. Return value 1.
MSI (s) (F4:AC) [18:37:48:939]: Doing action: LaunchApplication
MSI (s) (F4:AC) [18:37:48:939]: Note: 1: 2205 2: 3: ActionText
Action start 18:37:48: LaunchApplication.
MSI (s) (F4:AC) [18:37:48:939]: Creating MSIHANDLE (9) of type 790542 for thread 8108
MSI (s) (F4:B0) [18:37:48:939]: Invoking remote custom action. DLL: C:\Windows\Installer\MSIECB.tmp, Entrypoint: WixShellExec
MSI (s) (F4:24) [18:37:48:939]: Generating random cookie.
MSI (s) (F4:24) [18:37:48:939]: Created Custom Action Server with PID 8596 (0x2194).
MSI (s) (F4:48) [18:37:48:970]: Running as a service.
MSI (s) (F4:48) [18:37:48:970]: Hello, I'm your 32bit Impersonated custom action server.
MSI (s) (F4!74) [18:37:49:001]: Creating MSIHANDLE (10) of type 790541 for thread 1140
MSI (s) (F4!74) [18:37:49:001]: Creating MSIHANDLE (11) of type 790531 for thread 1140
MSI (s) (F4!74) [18:37:49:001]: Closing MSIHANDLE (11) of type 790531 for thread 1140
MSI (s) (F4!74) [18:37:49:001]: Creating MSIHANDLE (12) of type 790531 for thread 1140
WixShellExec: Error 0x80070002: ShellExec failed with return code 2
MSI (s) (F4!74) [18:37:49:001]: Closing MSIHANDLE (12) of type 790531 for thread 1140
MSI (s) (F4!74) [18:37:49:017]: Creating MSIHANDLE (13) of type 790531 for thread 1140
WixShellExec: Error 0x80070002: failed to launch target
MSI (s) (F4!74) [18:37:49:017]: Closing MSIHANDLE (13) of type 790531 for thread 1140
MSI (s) (F4!74) [18:37:49:017]: Closing MSIHANDLE (10) of type 790541 for thread 1140
CustomAction LaunchApplication returned actual error code 1603 (note this may not be 100% accurate if translation happened inside sandbox)
MSI (s) (F4:B0) [18:37:49:017]: Closing MSIHANDLE (9) of type 790542 for thread 8108
Action ended 18:37:49: LaunchApplication. Return value 3.
Action ended 18:37:49: INSTALL. Return value 3.
...
Property(N): WixShellExecTarget = [#start.vbs]
...
CustomAction returned actual error code 1603 (note this may not be 100% accurate if translation happened inside sandbox)
MSI (s) (F4:0C) [18:37:49:017]: Note: 1: 2262 2: Error 3: -2147287038
MSI (s) (F4:0C) [18:37:49:017]: Note: 1: 2262 2: Error 3: -2147287038
Action ended 18:37:49: RemoveExistingProducts. Return value 3.
MSI (s) (F4:0C) [18:37:49:017]: User policy value 'DisableRollback' is 0
MSI (s) (F4:0C) [18:37:49:017]: Machine policy value 'DisableRollback' is 0
MSI (s) (F4:0C) [18:37:49:017]: Executing op: Header(Signature=1397708873,Version=500,Timestamp=1190565049,LangId=1033,Platform=0,ScriptType=2,ScriptMajorVersion=21,ScriptMinorVersion=4,ScriptAttributes=0)
MSI (s) (F4:0C) [18:37:49:017]: Executing op: DialogInfo(Type=0,Argument=1033)
MSI (s) (F4:0C) [18:37:49:017]: Executing op: DialogInfo(Type=1,Argument=TestApp 1.0.0)
MSI (s) (F4:0C) [18:37:49:017]: Executing op: RollbackInfo(,RollbackAction=Rollback,RollbackDescription=Rolling back action:,RollbackTemplate=[1],CleanupAction=RollbackCleanup,CleanupDescription=Removing backup files,CleanupTemplate=File: [1])
MSI (s) (F4:0C) [18:37:49:017]: Executing op: SetTargetFolder(Folder=C:\Users\user1\AppData\Local\Programs\TestManufacturer\TestApp 1.0.0\)
MSI (s) (F4:0C) [18:37:49:017]: Executing op: FileCopy(SourceName=C:\Config.Msi\1bc1cc05.rbf,,DestName=C:\Users\user1\AppData\Local\Programs\TestManufacturer\TestApp 1.0.0\start.vbs,Attributes=40992,FileSize=331,PerTick=0,,VerifyMedia=0,ElevateFlags=1,,,,,,,InstallMode=4194308,,,,,,,)
MSI (s) (F4:0C) [18:37:49:017]: File: C:\Users\user1\AppData\Local\Programs\TestManufacturer\TestApp 1.0.0\start.vbs; To be installed; Won't patch; No existing file
...
MSI (s) (F4:0C) [18:37:49:126]: Executing op: End(Checksum=0,ProgressTotalHDWord=0,ProgressTotalLDWord=0)
MSI (s) (F4:0C) [18:37:49:126]: Error in rollback skipped. Return: 5
MSI (s) (F4:0C) [18:37:49:126]: No System Restore sequence number for this installation.
MSI (s) (F4:0C) [18:37:49:126]: Unlocking Server
MSI (s) (F4:0C) [18:37:49:173]: Note: 1: 2205 2: 3: Control
Action ended 18:37:49: INSTALL. Return value 3.
...
MSI (s) (F4:0C) [18:37:49:173]: MainEngineThread is returning 1603
MSI (s) (F4:78) [18:37:49:173]: RESTART MANAGER: Session closed.
MSI (s) (F4:78) [18:37:49:173]: RESTART MANAGER: Session closed.
MSI (s) (F4:78) [18:37:49:173]: No System Restore sequence number for this installation.
MSI (s) (F4:78) [18:37:49:173]: User policy value 'DisableRollback' is 0
MSI (s) (F4:78) [18:37:49:173]: Machine policy value 'DisableRollback' is 0
MSI (s) (F4:78) [18:37:49:173]: Incrementing counter to disable shutdown. Counter after increment: 0
MSI (s) (F4:78) [18:37:49:173]: Note: 1: 1402 2: HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Installer\Rollback\Scripts 3: 2
MSI (s) (F4:78) [18:37:49:173]: Note: 1: 1402 2: HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Installer\Rollback\Scripts 3: 2
MSI (s) (F4:78) [18:37:49:189]: Decrementing counter to disable shutdown. If counter >= 0, shutdown will be denied. Counter after decrement: -1
MSI (s) (F4:78) [18:37:49:189]: Restoring environment variables
MSI (s) (F4:78) [18:37:49:189]: Destroying RemoteAPI object.
MSI (s) (F4:24) [18:37:49:189]: Custom Action Manager thread ending.
MSI (c) (A8:A4) [18:37:49:189]: Back from server. Return value: 1603
MSI (c) (A8:A4) [18:37:49:189]: Decrementing counter to disable shutdown. If counter >= 0, shutdown will be denied. Counter after decrement: -1
MSI (c) (A8:A4) [18:37:49:189]: PROPERTY CHANGE: Deleting SECONDSEQUENCE property. Its current value is '1'.
Action ended 18:37:49: ExecuteAction. Return value 3.
Action ended 18:37:49: INSTALL. Return value 3.
...
=== Logging stopped: 7/22/2015 18:37:49 ===
MSI (c) (A8:A4) [18:37:49:189]: Note: 1: 1708
MSI (c) (A8:A4) [18:37:49:189]: Note: 1: 2262 2: Error 3: -2147287038
MSI (c) (A8:A4) [18:37:49:189]: Note: 1: 2262 2: Error 3: -2147287038
MSI (c) (A8:A4) [18:37:49:189]: Product: TestApp 2.0.0 -- Installation failed.
As I understand the root cause problem is that I do not use "NOT Installed AND NOT UPGRADINGPRODUCTCODE" condition in custom action LaunchApplication.
<Custom Action="LaunchApplication" After="InstallFinalize">NOT Installed AND NOT UPGRADINGPRODUCTCODE</Custom>
In this case installer during installation of new version removes the old version, and then tries to run custom action LaunchApplication from the old version, but all files are already removed. That's why installation fails.
I added condition "NOT Installed AND NOT UPGRADINGPRODUCTCODE" to LaunchApplication and now it is possible to perform major upgrade of my application.
But I am not sure which condition should I use - "NOT Installed AND NOT UPGRADINGPRODUCTCODE" or "NOT Installed".
I need to run custom action LaunchApplication during first installation and during all major upgrades.
Not sure this is an answer but there's too much for a comment.
First, do the upgrades with verbose logging, msiexec.exe command with a /L*vx to see what's going on because there are a number of things that don't make sense.
Your custom action is after InstallFinalize, which means it is after the install has completed and committed so it cannot cause the the upgrade to fail.
Your RemoveExistingProducts is before InstallInitialize. This means that it is outside the install transaction that starts at InstallInitialize. It really needs to be just after InstallInitialize to be included in the transation because currently it is independent of your new product install, and so you can get any combination of the remove failing or working and your install failing or working and you can end up with an indeterminate set of products on your system. None, noth or one of them.
What's SELFFOUND? I'd expect an Upgrade element to refer to it but there isn't one. In general you should look at the MajorUpgrade element and set attributes such as AllowSameVersionUpgrades to No if you want to prevent installing a major upgrade with the same version. If SELFFOUND is intended to prevent installing the same MSI file twice, then don't bother because Windows won't let you do that anyway.
So there's not really enough info to see what's going on, but that CA can't be responsible. The most likely explanation is that the first upgrade fails - it removes the older product, then your new install fails, and because the remove is outside the transaction all you see is the remove working and your install failing. When you install again it's a fresh system, that's the main difference. Check the logs!

How to launch executable after installation (exe is delivered by .msm)

I did everything as explained in tutorial, but my executable wasn't launched after product installation completed.
There is a nuance that my executable is delivered with .msm module, so in .wxs file for .msi I do the following to launch application:
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product>
<!-- I omit here features and elements which are irrelevant to the question-->
<Feature Id="Configurator" Display="hidden" Level="1">
<MergeRef Id="MergeConfigurator"/>
</Feature>
<UI>
<UIRef Id="WixUI_Minimal"/>
<Publish Dialog="ExitDialog" Control="Finish" Event="DoAction"
Value="LaunchConfigurator">WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1 and NOT Installed</Publish>
</UI>
<Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOXTEXT" Value="!(loc.ExitDlgCheckBoxText)" />
<Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOX" Value="1"/>
<Property Id="WixShellExecTarget" Value="[#SystemConfigurator.exe.81c0fa8f-9a8e-49d8-9dc2-ce01ca163146]" />
<CustomAction Id="LaunchConfigurator" BinaryKey="WixCA" DllEntry="WixShellExec" Impersonate="yes" />
</Product>
<Fragment>
<DirectoryRef Id="TARGETDIR">
<Merge Id="MergeConfigurator" SourceFile="$(var.MergeModulesPath)\ConfiguratorSetup_$(var.Platform).msm" DiskId="1" Language="1033"/>
</DirectoryRef>
</Fragment>
</Wix>
For the property with Id=WixShellExecTarget I have tried to pass value both with and without GUID (this is Package/#Id of .msm with my executable).
I opened my .msi with Orca and saw the exact ID of my executable (it's SystemConfigurator.exe.81c0fa8f-9a8e-49d8-9dc2-ce01ca163146, that's why I pass this very value).
But what it's wrong?
I logged installation process using /l*v option, and there is a portion from log:
Action 18:47:57: LaunchConfigurator.
Action start 18:47:57: LaunchConfigurator.
MSI (c) (54:68) [18:47:58:106]: Invoking remote custom action. DLL: C:\Users\AAGENO~1\AppData\Local\Temp\MSIB233.tmp, Entrypoint: WixShellExec
MSI (c) (54:08) [18:47:58:106]: Cloaking enabled.
MSI (c) (54:08) [18:47:58:106]: Attempting to enable all disabled privileges before calling Install on Server
MSI (c) (54:08) [18:47:58:106]: Connected to service for CA interface.
MSI (c) (54!04) [18:47:58:476]: Note: 1: 2715 2: SystemConfigurator.Client.exe.81c0fa8f-9a8e-49d8-9dc2-ce01ca163146
MSI (c) (54!04) [18:47:58:476]: Note: 1: 2715 2: SystemConfigurator.Client.exe.81c0fa8f-9a8e-49d8-9dc2-ce01ca163146
Action ended 18:47:58: LaunchConfigurator. Return value 3.
MSI (c) (54:34) [18:47:58:476]: Note: 1: 2205 2: 3: Error
MSI (c) (54:34) [18:47:58:476]: Note: 1: 2228 2: 3: Error 4: SELECT `Message` FROM `Error` WHERE `Error` = 2896
DEBUG: Error 2896: Executing action LaunchConfigurator failed.
Error 2715 means that the file key you're using isn't actually in the file table. Assuming it's referring to SystemConfigurator.exe.81c0fa8f-9a8e-49d8-9dc2-ce01ca163146 I would open the MSI file with Orca and see if that is the correct value AND keep in mind that Windows Installer proiperties are case-sensitive so if if it really is upper-case then use upper case. Make sure it really is a dash too, and not an underscore.

Installer generated by wix to update older version doesn't remove folder

I have 2 msi installers generated by WiX. First one (Installer 1) has version = "1.0.0.0", while second (Installer 2) has version = "1.1.0.0". Both of them have ProductCode = "*" and UpgradeCode= "UpgradeCode".
Installer 1 installs an exe file in %AppData%\MyApp\1.0.0.0 folder and also writes an entry in registry under SOFTWARE\MyApp\1.0.0.0. Value of the entry is 1.0.0.0
The expected behavior of Installer 2 is that during its installation previous version (1.0.0.0) will be unistalled from Control Panel, its entry will be deleted from registry, and folder will be unistalled from %AppData%\MyApp.
What really happens is that version 1.0.0.0 is unistalled from Control Panel, entry is deleted from registry and the new version's entry is installed but folder %AppData%\MyApp\1.0.0.0 remains there and a new folder 1.1.0.0 is created under %AppData%\MyApp.
Could anyone help me find what is wrong with my code and how I can solve it?
<Product Id="*"
Name="MyApplication"
Language="1033"
Version="$(var.ProductVersion)"
Manufacturer="MyCompany"
UpgradeCode="{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}">
<Package InstallerVersion="200"
Compressed="yes"
Description="Installer for my application"
InstallScope="perUser"/>
<Upgrade Id="{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}">
<UpgradeVersion Minimum="$(var.ProductVersion)"
OnlyDetect="yes"
Property="NEWERVERSIONDETECTED"/>
<UpgradeVersion Property="OLDERVERSIONBEINGUPGRADED"
Minimum="1.0.0.0"
IncludeMinimum="yes"
Maximum="$(var.ProductVersion)"
IncludeMaximum="no"/>
</Upgrade>
<Property Id="MSIRESTARTMANAGERCONTROL"
Value="Disable"/>
<InstallExecuteSequence>
<RemoveExistingProducts Before="InstallInitialize" />
</InstallExecuteSequence>
<Media Id="1"
Cabinet="MyApp.cab"
EmbedCab="yes"/>
<Directory Id="TARGETDIR"
Name="SourceDir">
<Directory Id="AppDataFolder">
<Directory Id="CompanyDir"
Name="MyApp">
<Component Id="CompanyDirComp"
Guid="*">
<RemoveFolder Id="RemCompanyDir"
On="uninstall"
Property="CompanyDir"/>
<RegistryValue Root="HKCU"
Key="SOFTWARE\MyApp"
Name="Uninstall"
Type="string"
Value="$(var.ProductVersion)"
KeyPath="yes"/>
<RemoveRegistryKey Action="removeOnInstall"
Id="cd"
Key="SOFTWARE\MyApp"
Root="HKCU"/>
</Component>
<Directory Id="INSTALLDIR"
Name="$(var.ProductVersion)">
<Component Id="CompanyDirInstallComp"
Guid="{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}">
<RegistryValue Root="HKCU"
Key="SOFTWARE\MyApp\$(var.ProductVersion)"
Name="Uninstall"
Type="string"
Value="$(var.ProductVersion)"
KeyPath="yes"/>
<RemoveFolder Id="RemINSTALLDIR"
On="uninstall"
Property="INSTALLDIR"/>
<File Id="myFile.exe" Source="C:\Users\myFile.exe"/>
<RemoveFile Id="RemMyFile"
On="uninstall"
Name="*.exe"/>
</Component>
</Directory>
</Directory>
</Directory>
</Directory>
</Product>
Updated question:
I have tested the above code on Windows 8.1x32 and Windows 8.1x64. Installer 2 works as it should on Windows 8.1x64; during its installation previous version (1.0.0.0) is unistalled from Control Panel, its entry is deleted from registry, and folder is unistalled from %AppData%\MyApp. On Windows 8.1x32 installer 2 only unistalls previous version from Control Panel but its entry remains in registry and folder is not deleted.
I ran installer 2 using cmd and the following command:
msiexec /i installer2.msi /l*v log.txt
Windows 8.1x64 output:
Action 2:45:13: FindRelatedProducts. Searching for related applications
Action start 2:45:13: FindRelatedProducts.
FindRelatedProducts: Found application: {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}
MSI (c) (48:7C) [02:45:13:828]: PROPERTY CHANGE: Adding OLDER_VERSION_DETECTED property. Its value is '{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}'.
Action ended 2:45:13: FindRelatedProducts. Return value 1.
Windows 8.1x32 output:
MSI (c) (68:20) [01:45:29:831]: Doing action: FindRelatedProducts
MSI (c) (68:20) [01:45:29:831]: Note: 1: 2205 2: 3: ActionText
Action 1:45:29: FindRelatedProducts. Searching for related applications
Action start 1:45:29: FindRelatedProducts.
Action ended 1:45:29: FindRelatedProducts. Return value 1.
For some reason on Windows 8.1x32 installer 2 cannot find version 1.0.0.0
Any ideas what can cause the issue mentioned above?