Set up the UI dialogs and install path conditionnally with WiX - wix

I know this is a common issue with WiX and I am aware that a solution for this might be easy, but I am stuck and none of the topics I could find helped me so here I go.
I'm using WiX 3.11 in Visual Studio with a very simple UI dialog sequence, which is taken from the wix documentation examples:
<Property Id="WIXUI_INSTALLDIR" Value="INSTALLFOLDER" />
<UI>
<UIRef Id="WixUI_InstallDir"/>
<Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="InstallDirDlg" Order="2"> 1 </Publish>
<Publish Dialog="InstallDirDlg" Control="Back" Event="NewDialog" Value="WelcomeDlg" Order="2"> 1 </Publish>
</UI>
Where INSTALLFOLDER is defined somewhere else in my directories definition.
As you can see, this is pretty straightforward:
- Welcome
- Choose a directory
- End the installation
Now, I would like to modify this set up to skip the InstallDir dialog when the .msi is upgrading, and do the upgrade directly in the existing install folder.
I have written a registry value in HKCU which stores the install path, and used a property to retrieve it when installing.
I tried to use conditions to create a different dialog sequence in the UI and set the install folder according to my property, but it ended up with errors when running the .msi file.
Here is what it looks like now:
<Product ...Some stuff here ... >
<Property Id="ALREADYINSTALLED">
<RegistrySearch Id="InstallPath"
Key="Software\$(var.MainDir)\$(var.SecondaryDir)"
Name="InstallFolder"
Root="HKCU"
Type="directory"
Win64="$(var.Win64)"/>
</Property>
<Property Id="WIXUI_INSTALLDIR" Value="INSTALLFOLDER" />
<UI>
<UIRef Id="WixUI_InstallDir"/>
<Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="InstallDirDlg" Order="2"> <![CDATA[NOT ALREADYINSTALLED]]> </Publish>
<Publish Dialog="InstallDirDlg" Control="Back" Event="NewDialog" Value="WelcomeDlg" Order="2"> <![CDATA[NOT ALREADYINSTALLED]]> </Publish>
/!\ Interesting part here /!\
<Publish Dialog="WelcomeDlg" Control="Next" Event="SetTargetPath" Value="[ALREADYINSTALLED]" Order="2"> <![CDATA[ALREADYINSTALLED]]> </Publish>
<Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="VerifyReadyDlg" Order="2"> <![CDATA[ALREADYINSTALLED]]> </Publish>
</UI>
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="$(var.PlatformProgramFilesFolder)">
<Directory Id="SAFEFOLDER" Name="$(var.MainDir)">
<Directory Id="INSTALLFOLDER" Name="$(var.SecondaryDir)" />
</Directory>
</Directory>
</Directory>
</Fragment>
<Component ... Some stuff here ... >
<RegistryValue Root="HKCU"
Key="Software\$(var.MainDir)\$(var.SecondaryDir)"
Name="InstallFolder"
Type="string"
Value="[INSTALLFOLDER]"
KeyPath="yes" />
... Some other stuff here ...
</Component>
My conditions seems to be working fine, but I couldn't pass the install folder using the property.
I feel I'm missing something simple, but I can't figure out what.
Can anybody help me please?

Well, I ended up finding a solution thanks to this topic. As I thought, it was quite simple.
It turns out you can override a directory path in the fragment definition so the solution was:
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="$(var.PlatformProgramFilesFolder)">
<Directory Id="SAFEFOLDER" Name="$(var.MainDir)">
<Directory Id="INSTALLFOLDER" Name="$(var.SecondaryDir)" />
</Directory>
</Directory>
</Directory>
<!-- Overwrites the Install Folder if this is an upgrade -->
<SetDirectory Id="INSTALLFOLDER" Value="[ALREADYINSTALLED]"> <![CDATA[ALREADYINSTALLED]]> </SetDirectory>
</Fragment>
Then, set up the UI dialogs to go from WelcomeDlg to VerifyReadyDlg:
<UI>
<UIRef Id="WixUI_InstallDir"/>
<Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="InstallDirDlg" Order="2"> <![CDATA[NOT ALREADYINSTALLED]]> </Publish>
<Publish Dialog="InstallDirDlg" Control="Back" Event="NewDialog" Value="WelcomeDlg" Order="2"> <![CDATA[NOT ALREADYINSTALLED]]> </Publish>
<Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="VerifyReadyDlg" Order="2"> <![CDATA[ALREADYINSTALLED]]> </Publish>
<Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="WelcomeDlg" Order="2"> <![CDATA[ALREADYINSTALLED]]> </Publish>
</UI>
And you're good to go.

Related

Wix Custom Dialog Error : ICE03: Not a valid foreign key Visual Studio 2019

I want to customize the sequence wix installer by having a custom dialog where I can process an input from a user before proceeding into the installation
I use the
<UI Id="WixUI_Minimal">
<TextStyle Id="WixUI_Font_Normal" FaceName="Tahoma" Size="8" />
<TextStyle Id="WixUI_Font_Bigger" FaceName="Tahoma" Size="12" />
<TextStyle Id="WixUI_Font_Title" FaceName="Tahoma" Size="9" Bold="yes" />
<Property Id="DefaultUIFont" Value="WixUI_Font_Normal" />
<Property Id="WixUI_Mode" Value="Minimal" />
<!--Define all needed dialogs-->
<DialogRef Id="ErrorDlg" />
<DialogRef Id="FatalError" />
<DialogRef Id="FilesInUse" />
<DialogRef Id="MsiRMFilesInUse" />
<DialogRef Id="PrepareDlg" />
<DialogRef Id="ProgressDlg" />
<DialogRef Id="ResumeDlg" />
<DialogRef Id="UserExit" />
<DialogRef Id="WelcomeDlg" />
<DialogRef Id="UserRegDialog" />
<Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="UserRegDialog">1</Publish>
<Publish Dialog="UserRegDialog" Control="" Event="NewDialog" Value="PrepareDlg">1</Publish>
<Publish Dialog="MaintenanceWelcomeDlg" Control="Next" Event="NewDialog" Value="MaintenanceTypeDlg" Order="2">2</Publish>
<Publish Dialog="MaintenanceTypeDlg" Control="RepairButton" Event="NewDialog" Value="VerifyReadyDlg" Order="2">2</Publish>
<Publish Dialog="MaintenanceTypeDlg" Control="RemoveButton" Event="NewDialog" Value="VerifyReadyDlg" Order="2">2</Publish>
<Publish Dialog="MaintenanceTypeDlg" Control="Back" Event="NewDialog" Value="MaintenanceWelcomeDlg" Order="2">2</Publish>
<Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="MaintenanceTypeDlg" Order="2">2</Publish>
<Publish Dialog="ExitDialog" Control="Finish" Event="EndDialog" Value="Return" Order="999">2</Publish>
<Property Id="ARPNOMODIFY" Value="1" />
</UI>
My customization is in the part :
where UserRegDialog is my custom dialog
<Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="UserRegDialog">1</Publish>
<Publish Dialog="UserRegDialog" Control="" Event="NewDialog" Value="PrepareDlg">1</Publish>
but when I build the setup, i'm encountering an issue saying:
ICE03: Not a valid foreign key; Table: ControlEvent, Column: Control_, Key(s): UserRegDialog.Next.NewDialog.PrepareDlg.
ICE & ICE3: ICE03 in general explained with an example here.
Referential Integrity: You have left out the Control field for UserRegDialog empty. Why did you do this? This will indeed likely cause ICE03 as this constitutes a broken foreign key into the ControlEvent table (as you will see it has foreign keys into the Dialog and Control tables).
Dialog Sequence: Here is an example on customizing WiX dialog sequence. Have a look to see if it clarifies things. Here is a sample on custom WiX dialogs.

Wix conditional registry writing based on the user choice

I use WiX 3.9 and WixUI_Advanced dialog to create a windows installer. The user has the possibility to choose to install the app locally or per machine (all users). For that i use the WixPerUserFolder property.
<Publish Dialog="InstallScopeDlg" Control="Next" Property="WixAppFolder" Value="WixPerUserFolder" Order="1">!(wix.WixUISupportPerUser) AND NOT Privileged</Publish>
<Publish Dialog="InstallScopeDlg" Control="Next" Property="MSIINSTALLPERUSER" Value="1" Order="8">WixAppFolder = "WixPerUserFolder"</Publish>
<Publish Dialog="InstallScopeDlg" Control="Next" Property="MSIINSTALLPERUSER" Value="{}" Order="9">WixAppFolder = "WixPerMachineFolder"</Publish>
<Publish Dialog="InstallScopeDlg" Control="Next" Property="ALLUSERS" Value="{}" Order="3">WixAppFolder = "WixPerUserFolder"</Publish>
<Publish Dialog="InstallScopeDlg" Control="Next" Property="ALLUSERS" Value="1" Order="2">WixAppFolder = "WixPerMachineFolder"</Publish>
<Publish Dialog="InstallScopeDlg" Control="Next" Property="APPLICATIONFOLDER" Value="[WixPerUserFolder]" Order="4">WixAppFolder = "WixPerUserFolder"</Publish>
<Publish Dialog="InstallScopeDlg" Control="Next" Property="APPLICATIONFOLDER" Value="[WixPerMachineFolder]" Order="5">WixAppFolder = "WixPerMachineFolder"</Publish>
Based on user choice (WixPerUserFolder or WixPerMachineFolder) i also want to be able to choose the registry key: HKCU or HKLM.
If the user selects for local installation then:
<RegistryKey Root="HKCU" Key="$(var.RegKey)" ForceDeleteOnUninstall="yes" ForceCreateOnInstall="yes">
<RegistryValue Type="string" Value="" KeyPath="yes" />
<RegistryValue Type="string" Name="InstallDir" Value="[INSTALLDIR]"/>
</RegistryKey>
otherwise:
<RegistryKey Root="HKLM" Key="$(var.RegKey)" ForceDeleteOnUninstall="yes" ForceCreateOnInstall="yes">
<RegistryValue Type="string" Value="" KeyPath="yes" />
<RegistryValue Type="string" Name="InstallDir" Value="[INSTALLDIR]"/>
</RegistryKey>
Root="HKMU" will pick the right hive based on whether the package is run per-user or per-machine.

How to prevent installation exit dialog from showing when the user has uninstalled? [WiX]

I have made a custom exit dialog for my installer. The problem is that it is shown when the user uninstalls the program, when I would like the default uninstall exit dialog to be shown instead.
My installer code is viewable at Github. I think the relevant code is:
<Publish Dialog="KerkerkruipExitDialog" Control="Finish" Event="EndDialog" Value="Return" Order="999">1</Publish>
<Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="MaintenanceTypeDlg">1</Publish>
<Publish Dialog="MaintenanceWelcomeDlg" Control="Next" Event="NewDialog" Value="MaintenanceTypeDlg">1</Publish>
<Publish Dialog="MaintenanceTypeDlg" Control="RepairButton" Event="NewDialog" Value="VerifyReadyDlg">1</Publish>
<Publish Dialog="MaintenanceTypeDlg" Control="RemoveButton" Event="NewDialog" Value="VerifyReadyDlg">1</Publish>
<Publish Dialog="MaintenanceTypeDlg" Control="Back" Event="NewDialog" Value="MaintenanceWelcomeDlg">1</Publish>
<Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="VerifyReadyDlg">Installed AND PATCH</Publish>
<Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="WelcomeDlg" Order="2">Installed AND PATCH</Publish>
<InstallUISequence>
<Show Dialog="WelcomeDlg" Before="KerkerkruipWelcomeEulaDlg">Installed AND PATCH</Show>
<Show Dialog="KerkerkruipWelcomeEulaDlg" Before="ProgressDlg">NOT Installed</Show>
<Show Dialog="KerkerkruipExitDialog" OnExit="success" Overridable="yes" />
</InstallUISequence>
<AdminUISequence>
<Show Dialog="KerkerkruipExitDialog" OnExit="success" Overridable="yes" />
</AdminUISequence>
You can have only one exit dialog for success. MSI doesn't let you have different success exit dialogs for different operations like install or uninstall. From the MSI SDK:
Each termination flag (negative value) can be used with no more than one action. Multiple actions can have termination flags, but they must be different flags.

New dialog in WiX, clicking Back skips the dialog

I'm newbie in WiX and trying to customize dialog queue by adding the new one. The new dialog's name is ServerChoice and the flow is:
SetupTypeDlg <-> Full or Typical <-> ServerChoice <-> VerifyReadyDlg
or
SetupTypeDlg <-> Custom <-> CustomizeDlg <-> ServerChoice <-> VerifyReadyDlg
The only problem is in the first case at VerifyReadyDlg. 'Back' takes me to SetupTypeDlg and skips ServerChoice although in the second flow it works as required.
Source:
<UI>
<DialogRef Id="ServerChoice" />
<Publish Dialog="SetupTypeDlg" Control="TypicalButton" Event="NewDialog" Value="ServerChoice">1</Publish>
<Publish Dialog="SetupTypeDlg" Control="CompleteButton" Event="NewDialog" Value="ServerChoice">1</Publish>
<Publish Dialog="CustomizeDlg" Control="Next" Event="NewDialog" Value="ServerChoice">1</Publish>
<Publish Dialog="ServerChoice" Control="Next" Event="NewDialog" Value="VerifyReadyDlg">1</Publish>
<Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="ServerChoice">1</Publish>
<Publish Dialog="ServerChoice" Control="Back" Event="NewDialog" Value="CustomizeDlg" Order="1">WixUI_InstallMode = "InstallCustom"</Publish>
<Publish Dialog="ServerChoice" Control="Back" Event="NewDialog" Value="SetupTypeDlg" Order="2">WixUI_InstallMode = "InstallTypical" OR WixUI_InstallMode = "InstallComplete"</Publish>
<Publish Dialog="ServerChoice" Control="Back" Event="NewDialog" Value="CustomizeDlg" Order="3">WixUI_InstallMode = "Change"</Publish>
<Publish Dialog="ServerChoice" Control="Back" Event="NewDialog" Value="MaintenanceTypeDlg" Order="4">WixUI_InstallMode = "Repair" OR WixUI_InstallMode = "Remove"</Publish>
</UI>
Some help for a newbie? :)
What type of UI are you referencing (Mondo?). This information is not present in your piece of code. I think daddyman's comment is right, you probably have multiple events for that Back button, since Mondo itself hooks its own 'handlers' on this button-click event.
I have created a custom UI dialog flow recently and my approach was not referencing WiXUI_Mondo at all. Instead of it, I created my own new UI based on Mondo source code (you have to check WiX sources). At the end I have this code (irrelevant code parts have been removed) and it works fine.
<Fragment>
<!-- this is based on the WixUI_Mondo dialog set -->
<UI Id="WixUI_MyNewUI">
<TextStyle Id="WixUI_Font_Normal" FaceName="Tahoma" Size="8" />
<TextStyle Id="WixUI_Font_Bigger" FaceName="Tahoma" Size="12" />
<TextStyle Id="WixUI_Font_Title" FaceName="Tahoma" Size="9" Bold="yes" />
<Property Id="DefaultUIFont" Value="WixUI_Font_Normal" />
<Property Id="WixUI_Mode" Value="Mondo" />
<DialogRef Id="ErrorDlg" />
<DialogRef Id="FatalError" />
<DialogRef Id="FilesInUse" />
<DialogRef Id="MsiRMFilesInUse" />
<DialogRef Id="PrepareDlg" />
<DialogRef Id="ProgressDlg" />
<DialogRef Id="ResumeDlg" />
<DialogRef Id="UserExit" />
<Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="CustomizeDlg">1</Publish>
<!-- we do not use the SetupTypeDlg which allows user to choose either Typical, Complete or Custom installation; this ensures InstallCustom schema is run -->
<Publish Dialog="WelcomeDlg" Control="Next" Property="WixUI_InstallMode" Value="InstallCustom" Order="2">1</Publish>
<Publish Dialog="CustomizeDlg" Control="Back" Event="NewDialog" Value="WelcomeDlg" Order="2">WixUI_InstallMode = "InstallCustom"</Publish>
<Publish Dialog="CustomizeDlg" Control="Next" Event="NewDialog" Value="MyDlg1">1</Publish>
<Publish Dialog="MyDlg1" Control="Next" Event="NewDialog" Value="VerifyReadyDlg" Order="1">MY_CONDITION_PROPERTY = 0</Publish>
<Publish Dialog="MyDlg1" Control="Next" Event="NewDialog" Value="MyDlg2" Order="2">MY_CONDITION_PROPERTY = 1</Publish>
<Publish Dialog="MyDlg2" Control="Next" Event="NewDialog" Value="VerifyReadyDlg" Order="1" />
<Publish Dialog="MyDlg2" Control="Back" Event="NewDialog" Value="MyDlg1">1</Publish>
<Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="MyDlg1" Order="1">WixUI_InstallMode = "InstallCustom" and MY_CONDITION_PROPERTY = 0</Publish>
<Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="MyDlg2" Order="2">WixUI_InstallMode = "InstallCustom" and MY_CONDITION_PROPERTY = 1</Publish>
</UI>
<UIRef Id="WixUI_Common" />
<UIRef Id="WixUI_ErrorProgressText" />
</Fragment>
I think from your fragment that you are trying to do it in a just UI section and I don't believe that is possible. Take a look here http://neilsleightholm.blogspot.com/2008/08/customised-uis-for-wix.html I think it should help.

How to build a minimal WiX installer UI without a license page?

I would like to use the WixUI_Minimal installer, but I don't want the license page. How can I do this?
I would simply use one of the already created WiX UI and override the sequence (make it higher so that it will override the previous setting):
<Product>
...
<UI>
<UIRef Id="WixUI_InstallDir" />
<!-- Skip license dialog -->
<Publish Dialog="WelcomeDlg"
Control="Next"
Event="NewDialog"
Value="InstallDirDlg"
Order="2">1</Publish>
<Publish Dialog="InstallDirDlg"
Control="Back"
Event="NewDialog"
Value="WelcomeDlg"
Order="2">1</Publish>
</UI>
<Property Id="WIXUI_INSTALLDIR" Value="INSTALLFOLDER" />
...
</Product>
The key is to make a custom UI and hook up different pages. See the page on WixWiki
You want to grab the WixUI minimal code, and modify it a bit. Instead of the WelcomeEulaDlg welcome dialog, you want to use the WelcomeDlg. Adjust the references, and wire up the Next button on the WelcomeDlg to the next dialog in the stack, which would be the PrepareDlg.
Full Code:
<UI Id="WixUI_Minimal">
<TextStyle Id="WixUI_Font_Normal" FaceName="Tahoma" Size="8" />
<TextStyle Id="WixUI_Font_Bigger" FaceName="Tahoma" Size="12" />
<TextStyle Id="WixUI_Font_Title" FaceName="Tahoma" Size="9" Bold="yes" />
<Property Id="DefaultUIFont" Value="WixUI_Font_Normal" />
<Property Id="WixUI_Mode" Value="Minimal" />
<DialogRef Id="ErrorDlg" />
<DialogRef Id="FatalError" />
<DialogRef Id="FilesInUse" />
<DialogRef Id="MsiRMFilesInUse" />
<DialogRef Id="PrepareDlg" />
<DialogRef Id="ProgressDlg" />
<DialogRef Id="ResumeDlg" />
<DialogRef Id="UserExit" />
<!-- This is the welcome dialog you specified-->
<DialogRef Id="WelcomeDlg" />
<!-- Hook the new welcome dialog to the next one in the stack-->
<Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="PrepareDlg">1</Publish>
<Publish Dialog="ExitDialog" Control="Finish" Event="EndDialog" Value="Return" Order="999">1</Publish>
<Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="MaintenanceTypeDlg">1</Publish>
<Publish Dialog="MaintenanceWelcomeDlg" Control="Next" Event="NewDialog" Value="MaintenanceTypeDlg">1</Publish>
<Publish Dialog="MaintenanceTypeDlg" Control="RepairButton" Event="NewDialog" Value="VerifyReadyDlg">1</Publish>
<Publish Dialog="MaintenanceTypeDlg" Control="RemoveButton" Event="NewDialog" Value="VerifyReadyDlg">1</Publish>
<Publish Dialog="MaintenanceTypeDlg" Control="Back" Event="NewDialog" Value="MaintenanceWelcomeDlg">1</Publish>
<Property Id="ARPNOMODIFY" Value="1" />
</UI>
<UIRef Id="WixUI_Common" />
The low-tech way to get around this is simply to set the property LicenseAccepted to 1 and put some useful readme type information into the license box. This means the user doesn't have to click the box and you don't have to worry about creating an additional dialog :)
Example:
<Property Id="LicenseAccepted" Value="1"/>
See the answer to a related question, WiX script with only Welcome and Completed screens, for the simplest minimal UI:
WelcomeDlg
Installation progress
Exit Dialog
#Ran Davidovitz 's answer is very good
but be carefully:
<Publish Dialog="InstallDirDlg"
Control="Back"
Event="NewDialog"
Value="WelcomeDlg"
Order="2">1</Publish>
it must have Order="2",or it can't work.