WiX. Rollback custom action when is canceled installation - wix

I have a custom action
<CustomAction Id="myActionId" BinaryKey="myAction" DllEntry="MySimpleAction" Execute="immediate" Return="check" />
<InstallExecuteSequence>
<Custom Action="myActionId" After="InstallInitialize">CHECKBOXCOPYPROP=1</Custom>
</InstallExecuteSequence>
My custom action does backup and resolved database. I need to do rollback (drop database) when is canceled installation.
I did:
<CustomAction Id="myActionId" BinaryKey="myAction" DllEntry="MySimpleAction" Execute="immediate" Return="check" />
<CustomAction Id="myActionRollbackId" BinaryKey="myActionRollback" DllEntry="MySimpleAction" Execute="rollback" Return="check" />
<InstallExecuteSequence>
<Custom Action="myActionId" After="InstallInitialize">CHECKBOXCOPYPROP=1</Custom>
<Custom Action="myActionRollbackId" Before="myActionId">CHECKBOXCOPYPROP=1</Custom>
</InstallExecuteSequence>
But I was having an error.
If I do like this:
<CustomAction Id="myActionId" BinaryKey="myAction" DllEntry="MySimpleAction" Execute="immediate" Return="check" />
<CustomAction Id="myActionRollbackId" BinaryKey="myActionRollback" DllEntry="MySimpleAction" Execute="immediate" Return="check" />
<InstallExecuteSequence>
<Custom Action="myActionId" After="InstallInitialize">CHECKBOXCOPYPROP=1</Custom>
<Custom Action="myActionRollbackId" After="myActionId">CHECKBOXCOPYPROP=1</Custom>
</InstallExecuteSequence>
My custom action myActionRollbackId works.
How to run rolback when is canceled installation?
Someone can help me?

The custom action which runs on install and does something with the database should be deferred (Execute='deferred'). Its corresponding rollback action should be Execute='rollback'. When you schedule these custom actions, the rollback action should go first.
Also, make sure the conditions are set properly.

Installation is always done in transaction. when you launch an installer, it first creates something called installation script which is like a to do list of what it will do while installation.
When we set some custom action as Execute="immediate", it gets executed immediately but when we set our action as Execute="deferred", it gets added in the installation script, hence rollback becomes easy for this.
Now one thing to note here is that we get access to session in Execute="immediate" mode, but we cannot access session in Execute="deferred" mode.
If we try to access session it will give error, which in this case might be the reason for your error...

Related

Wix - Running a deferred action after InstallFinalize

Reading the Wix help I see that "Deferred execution custom actions must come after InstallInitialize and come before InstallFinalize in the action sequence."
However I have to perform a database upgrade on a remote box which needs to be run with the user credentials so I have created an immediate action and set it to run after installFinalize. Subsequently, I need to run another custom action to start a windows service which reads values from the database, this requires elevated (system) permissions, so needs to be a deferred custom action. Which as the Wix help kindly explains to me that I cannot do.
Any help, tips or Wix tricks appreciated please
<CustomAction Id="LaunchServerUpgrade" FileKey="Config.exe" ExeCommand="/upgradeServer"
Return="ignore" Execute="deferred" Impersonate="no"/>
<CustomAction Id="LaunchServerDatabaseUpgrade" FileKey="Config.exe" ExeCommand=" /databaseupgrade"
Return="ignore" Execute="immediate"/>
<CustomAction Id="LaunchServerStartServices" FileKey="Config.exe" ExeCommand=" /startservices"
Return="ignore" Execute="deferred" Impersonate="no"/>
<InstallExecuteSequence>
<Custom Action="LaunchServerUpgrade" Before='InstallFinalize'>
<![CDATA[(SERVERCONFIGUPGRADE) AND NOT REMOVE)]]>
</Custom>
<Custom Action="LaunchServerDatabaseUpgrade" After='InstallFinalize'>
<![CDATA[(SERVERCONFIGUPGRADE) AND NOT REMOVE)]]>
</Custom>
<Custom Action="LaunchServerStartServices" After='InstallFiles'>
<![CDATA[(SERVERCONFIGUPGRADE) AND NOT REMOVE)]]>
</Custom>
</InstallExecuteSequence>

Unable to Silent Execute the Command in WiX Script

Below is my code when i try to install my MSI it does everything but the lines below shows no sign of execution.
<Binary Id="unzipExeId" SourceFile="unzip.exe"/>
<Property Id="WixQuietExec64CmdLine" Value="[#$(var.InstallationLocation)\unzip.exe]"/>
<CustomAction Id="unzipAction" BinaryKey="unzipExeId" DllEntry="WixQuietExec64" Execute='deferred' Return ='asyncWait' Impersonate='no'/>
<InstallExecuteSequence>
<Custom Action='unzipAction' Before='InstallFinalize'/>
</InstallExecuteSequence>
Did I miss anything.
But When i Try this code
<Binary Id="unzipExeId" SourceFile="unzip.exe"/>
<CustomAction Id="unzipAction" BinaryKey="unzipExeId" ExeCommand="START /B unzip.exe" Execute='deferred' Return ='asyncWait' Impersonate='no'/>
<InstallExecuteSequence>
<Custom Action='unzipAction' Before='InstallFinalize'/>
</InstallExecuteSequence>
Everything Works Just Fine but the execution of the unzip.exe causes a pop up in the machine. The exe is not silently installed. But i need to silently execute the EXE.
Thanks in Advance
It could be related to DllEntry instead of using "WixQuietExec64" try to use "CAWixQuietExec64".
There is an open issue regarding this.
http://wixtoolset.org/issues/4802/
This is as a common use:
<CustomAction Id="CA_RunBatchScript"
BinaryKey="WixCA"
DllEntry="CAQuietExec"
Execute="deferred"
Return="check" />

Triggering custom action in a silence mode

I'm working on a setup that validate many user inputs by a custom action. The event "DoAction" of publish control are doing very good job, but I figured out that no one custom validation are triggered if I execute the setup in silence mode.
I tried InstallExecuteSequence like the Yen Tran's blog (http://yentran.org/blog/2013/09/27/wix-executing-custom-action-before-starting-windows-service/) but still not working.
<Frament>
<Binary Id="CALibrary" SourceFile="$(var.Project.Installer.CustomAction.TargetDir)CustomAction.CA.dll" />
<CustomAction Id ="ProxyCheck" BinaryKey="CALibrary" DllEntry="Proxy" Execute="immediate" Return="check" />
<CustomAction Id ="ActivationCheck" BinaryKey="CALibrary" DllEntry="Activation" Execute="immediate" Return="check" />
</Frament>
...
<Fragment>
<InstallExecuteSequence>
<Custom Action="ActivationCheck" Before="InstallInitialize" Overridable="yes">PROXYSERVER</Custom>
</InstallExecuteSequence>
With Orca.exe I found that the action was not configured in InstallExecuteSequence no matter what I do. Reviewing all the files for the thousandth time, I found that I was putting the instruction of InstallExecuteSequence in a wrong place, moved into the <Product> </Product> and then everything works well.

Two simultaneous EXE files running WiX

I have two custom actions running two EXE files. But they get extracted at the same time and the processes block each other during install. How do I schedule them one after the other?
<CustomAction Id="StartAppOnExit1"
FileKey="UMIEXE"
ExeCommand=""
Execute="deferred"
Return="asyncNoWait"
Impersonate="no" />
<InstallExecuteSequence>
<Custom Action="StartAppOnExit1"
Before="InstallFinalize">$UMIEXE=3</Custom>
</InstallExecuteSequence>
<CustomAction Id="StartAppOnExit2"
FileKey="Python"
ExeCommand=""
Execute="commit"
Return="check"
Impersonate="no" />
<InstallExecuteSequence>
<Custom Action ="StartAppOnExit2"
After="StartAppOnExit1" >$Python=3</Custom>
</InstallExecuteSequence>
Here is my code, but I seem to be getting an error with what you told.
In product.wxs sequence them one after another and in custom action have a check to validate that the exe is executed and hold the process there only
<Custom Action="FirstCustomAction" After="InstallFinalize">NOT INSTALLED AND NOT REMOVE</Custom>
<Custom Action="SecondCustomAction" After="FirstCustomAction">NOT INSTALLED AND NOT REMOVE</Custom>
in CustomAction
WaitForExit() in process call.

When can I get the target directories in a WIX installer?

So I have a custom action
<CustomAction Id="GetTarget"
BinaryKey="CA"
DllEntry="GetTargetPath"
Execute="immediate"
Return="check"
HideTarget="no"
Impersonate="no" />
<InstallExecuteSequence>
<Custom Action="GetTarget" After="CostFinalize">(NOT REMOVE = "ALL")</Custom>
</InstallExecuteSequence>
This is calling a DLL that calls the method session.GetTargetPath("TARGETPATH"); But I get an exception "The directory name is invalid. TARGETPATH". I have the custom action as After="CostFinalize" as this is what I read from a source (which I can provide) but I think there is a mistake and I think that I just have to to execute the action at the right time.
I think you meant TARGETDIR. Take a look at http://msdn.microsoft.com/en-us/library/windows/desktop/aa371685(v=vs.85).aspx