Pass MSI Property before Install Finalize - wix

I have a variable in my burn bundle as such:
<Variable Name="DemoVariable" Type="string" Value="ChangedProperty" bal:Overridable="yes"/>
Which is then used with an MSIProperty:
<MsiPackage SourceFile="testFile.msi" Id="DemoPackageId_1" Cache="yes" Visible="no">
<MsiProperty Name="PassedProperty" Value="[DemoVariable]"/>
</MsiPackage>
In my testFile.msi I have a property and custom action:
<Property Id="PassedProperty" Value="Unchanged"/>
<Binary Id="CustomActionDll"
SourceFile="CustomAction.CA.dll"/>
<InstallExecuteSequence>
<Custom Action="ShowMessageBoxCA" Before="CostFinalize"/>
</InstallExecuteSequence>
<CustomAction Id="ShowMessageBoxCA"
Return="check"
Execute="firstSequence"
BinaryKey="CustomActionDll"
DllEntry="ShowMessageBox"
HideTarget="no" />
The ShowMessageBox function literally just calls:
MessageBox.Show(session["PassedProperty"])
The problem is that the message box shows the message "unchanged". I looked through the log file for the installation and I can see that the PassedProperty is being changed sometime after InstallFinalize finishes. This is obviously too late for my custom action which takes place before CostFinalize.
Is there a way to make Burn change the MSIProperty earlier in the process rather than making the custom actions take place later?
Edit:
Okay so I found the answer but I can't post it yet so I'll leave the information here in an edit.
Basically MSI's have Public and Private properties. Only public properties are declared before the install phase takes place. Public properties must be all uppercase so to fix my issue I just replaced all instance of "Passed_Property" with "PASSED_PROPERTY" and it works fine.

So the problem I had was that I was creating my properties as private properties, which aren't available until after the installation. To make your properties public and therefore available throughout the whole install, they need to be Uppercase.
<Property Id="PASSED_PROPERTY" Value="Unchanged"/>
https://msdn.microsoft.com/en-us/library/aa370912(v=vs.85).aspx
As soon as I made them public the properties were changed by Burn.

Related

Wix scheduling custom actions

In the process of converting from installshield to wix, I am porting over the custom actions.
One is for determining previously installed versions and popping up a message if any are found. I guess the guids weren't properly tracked before.
Within installshield, it appears they had the CA scheduled after ValidateProductID. I tried to do the same:
<CustomAction Id="CA_CheckPreviousVersions.SetProperty" Property="CA_CheckPreviousVersions" Value="ERROR_UNINSTALL_VERSION=$(var.ERROR_UNINSTALL_VERSION)" />
<CustomAction Id="CA_CheckPreviousVersions" DllEntry="CheckPreviousVersions" Execute="deferred" BinaryKey="LunaClientCustomActions_dll" />
<InstallExecuteSequence>
...
<Custom Action="CA_CheckPreviousVersions.SetProperty" After="ValidateProductID" />
<Custom Action="CA_CheckPreviousVersions" After="CA_CheckPreviousVersions.SetProperty" >NOT Installed AND NOT PATCH</Custom>
</InstallExecuteSequence>
Except, I get a nasty warning:
error LGHT0204: ICE77: CA_CheckPreviousVersions is a in-script custom action. It must be sequenced in between the InstallInitialize action and the InstallFinalize action in the InstallExecuteSequence table
Why am I getting this, whereas IS seemingly permitted it? More to the point, how do I replicate the behaviour that was previously in place?
You haven't shown the custom action definition, but the message indicates it's deferred and must be sequenced as the message indicates. Perhaps the original type was immediate.
If you mean previously installed versions of your product (or in fact any MSI-based product for which you know the UpgradeCode) there is no need for any code. If you were to use a WiX MajorUpgrade element you can detect previous versions because the WIX_UPGRADE_DETECTED property will be set, and you could use that as a launch condition, or whatever it is you plan to do. Or use Upgrade and UpgradeVersion elements to detect previous versions and version ranges. From what you've said there seems no need to run code. Just use the upgrade search properties and show dialogs or errors or whatever.

How to transfer a string from WIX installer to a VB script?

I have build an installer to install machine software. However the user is required to fill in one value (the machine ID) this because it needs to replace a value already present in the .INI file. The code to replace the value is no problem since I already got it working.
However I dont know how to get the value (for example: DE123654) from the WIX installer in the script that is being executed to replace the value using a WIX custom action. I created a Custom form for asking the value and the code i use to get the value is as following:
<Control Id="InputField" Type="Edit" X="20" Y="100" Width="140" Height="18" Property="MachineIdNumber" Text="{80}"/>
I found this code on this website, however I don't know how to get the value from here into my script or how I can make the script look up the value that has been entered. any suggestion on how I can achieve this?
I ask for the MachineID at the beginning of the installation process, so the value is known before the actual installation process starts.
the script is embedded in the installer and is being executed at the end of the installation process since the file that needs to be altered is already at the correct location on the targer system.
Thanks in advance,
You need to create a custom action to set the properties you want to pass and the Property value must be the same as the Id of the custom action calling the script, this way:
<Product ...>
<CustomAction
Id="SetProperties"
Property="ScriptCA"
HideTarget="yes"
Value="[MachineIdNumber];[OtherProperty]"
/>
<CustomAction
Id="ScriptCA"
BinaryKey="CustomActionsLib"
DllEntry="ScriptMethod"
Execute="deferred"
Impersonate="no"
Return="check"
/>
<InstallExecuteSequence>
<Custom Action="SetProperties" Before="ScriptCA" />
<Custom Action="ScriptCA" Before="InstallFinalize">NOT REMOVE="ALL"</Custom>
</InstallExecuteSequence>
</Product>

WIX Installer - Possible to Invoke Custom Action .exe Before `InstallFiles`?

I have an .exe embedded inside my MSI installer which I'd like to somehow call directly from the installer, before the the 'InstallFiles' action occurs.
It's defined as follows:
<CustomAction Id="LaunchInstallManager_TryUninstall" Return="ignore" Directory="INSTALLFOLDER" Execute="deferred" Impersonate="no" ExeCommand=""[#fil713F8F6A7BC9B98857D779B9B29873E1]" /someargument"></CustomAction>
<Custom Action="LaunchInstallManager_TryUninstall" Before="InstallFiles">NOT Installed</Custom>
But upon looking at the logs, it looks like it's (trying to be) called from the install destination.
Is such a thing possible?
It is possible, but in a different way. The 'run EXE' type of custom action will always search for the executable on the target system. Thus, if your executable is installed along with your app, it is not an option.
Here is another way:
First, author your EXE as a <Binary> instead.
It is as easy as <Binary Id="MyEXE" SourceFile="PATH\TO\EXE" />.
Add a DLL deferred custom action, which will extract the binary, run it with parameters and clean up afterwards.
This post can give you an idea how to extract the binary using C# and DTF. Besides, in case you need to pass parameters, make sure you do it the right way for deferred custom action.
Finally, remember that each deferred custom action (that is the one to change the target system) must have corresponding rollback action. This article might give you some hints on how to test the direct and rollback behaviors of your custom actions.

WiX Bootstrapper: Rollback notification

In the bundle.wxs of my managed bootstrapper, I have chained multiple packages:
<Chain>
<ExePackage Id="Test1"......>
<ExePackage Id="Test2"......>
<ExePackage Id="MicrosoftVCPP2005Redistributable" SourceFile="..\Tools\VC2005Redistributable\vcredist_x86.exe" Vital="yes" InstallCondition="SelectedDBSize1 = 24" />
</Chain>
I'm subscribing to the ExecutePackageBegin/ExecutePackageComplete events to check which package is currently being executed and accordingly display the progress text indicating which installation is in progress.
But, if due to some reason a roll back action starts midway, I want to change the progress text to indicate that rollback is in progress. Is there any event available when there is a switch from installation to rollback? Or do I have to check the sequence of the packages being invoked and decide based on that?
The documentation for the property is a little bit wrong but the ExecutePackageBeginEventArgs class's ShouldExecute property will tell you if the package is being "executed" or "rolled back". In your case, when the ExecutePackageBeginEventArgs.ShouldExecute=false then you know that package is being rolled back.

How to call custom action after files copied in wix

I want perform custom action after files are copy in destination folder.
In custom action i run copied script file so give me error file not found.
<CustomAction Id="RunDBScript"
BinaryKey="CA"
DllEntry="RunDBScript"
Execute=" immediate"
Return="check" />
<Custom Action="RunDBScript" After="InstallFiles">
<![CDATA[NOT Installed]]>
</Custom>
this custom action give an error file/directory not found. so this action call before file copy.
so, how to call custom action after file copy?
I am not understand why this custom action call before InstallFiles even though i am specified After="InstallFiles".
Move your custom action after InstallFinalize. This is the only place in InstallExecuteSequence where Immediate actions can be executed after installing the product files.
When you use deferred custom actions, you must access values through session.CustomActionData["propertyname"].
Session dictionary values can be read only by immediate custom actions, where the execution script is being written.
The deferred custom actions are executed at script running time, so the project properties are no longer available.
To make use of it, you must implement a double custom action in order to provide the desired properties for the real custom action.
Follow the bellow example:
<CustomAction Id="CustomActionID_Data" Property="CustomActionID" Value="INSTALLDIR=[INSTALLDIR];OTHERPROPERTY=[OTHERPRPJECTPROPERTY]"></CustomAction>
<CustomAction Id="CustomActionID" BinaryKey="FILEBINARYID" DllEntry="METHODNAMEATCUSTOMACTION" Execute="deferred"></CustomAction>
At this example, you need to call at InstallExecutionSequence the custom action "_Data" and after call the real one, so the first "_Data" will se the desired properties. Then you can access those properties on your code using session.CustomActionData[""].
Just complementing, bellow is an example of how to call the custom actions at InstallExecuteSequence.
<Custom Action="CustomActionID_Data" After="InstallFiles">NOT (REMOVE="ALL")</Custom>
<Custom Action="CustomActionID" After="CustomActionID_Data">NOT (REMOVE="ALL")</Custom>