3

I developed an installer using Wix 3.6 that installs successfully all elements of an application.

Now, each time I give an msi with a higher version, I want the installer to prompt the user to uninstall it. Since now I've tried this:

<Product 
Id="*" 
Name="!(loc.ProductName)" 
Language="3082" 
Codepage="1252"
Version="1.0.1"
Manufacturer="$(var.ProductManufacturer)" 
UpgradeCode="$(var.UpgradeCode)">

<Property Id="PREVIOUSVERSIONINSTALLED" Secure="yes" />
<Upgrade Id="$(var.UpgradeCode)">
  <UpgradeVersion Minimum="1.0.0.0" Maximum="99.9.9.9" IncludeMiminum="yes" IncludeMaximum="no" Property="PREVIOUSVERSIONSINSTALLED" />
</Upgrade>

<InstallExecuteSequence>
  <RemoveExistingProducts Before="InstallInitialize" />
</InstallExecuteSequence>

This code successfully uninstalls any previous installed version on my computer. But it doesn't ask the user if he's sure to do so.

What I need is Wix installer to prompt the user saying a message like:

A previous version of your [ProductName] is installed. Do you want to uninstall it? [ Yes | No ] option.

Is there any way to prompt user and check if he really wants to uninstall any previous version?

Sonhja
  • 8,230
  • 20
  • 73
  • 131

2 Answers2

2

The Windows Installer Upgrade table has an attribute bit called msidbUpgradeAttributesOnlyDetect that is represented by WiX's UpgradeVersion@OnlyDetect attribute.

When properly authored this causes FindRelatedProducts to set an action property of your choosing with the ProductCode GUID(s) of detected products. It does not pass this off to RemoveExistingProducts for automatic removal though.

While not the typical behavior, there is nothing stopping you from writing some UI that gets triggered when this property has a value. You could ask the user if they want to remove the old version and if yes, set another action property to tell RemoveExistingProducts. (Hint: Author a Upgrade that would never find a product on it's own and hijack it's property to inject the removal. )

If the user says no, you have the choice of aborting the install or continuing the install side by side to a different directory structure. ( Office, Visual Studio et al ).

Christopher Painter
  • 54,556
  • 6
  • 63
  • 100
  • Thanks Christopher. My first thought was to substitute the repair/change/remove window for one that fits my needs (as you comment). But I don't know why, when I install the application and try to install a new version afther that, it pushes me to the add/remove programs from panel control. For me, that choice would be the best one (create a custom interface). – Sonhja Aug 01 '13 at 10:26
  • Comming back to your solution: can you explain a bit more how to use the solution you explain? I get lost on how to apply it. – Sonhja Aug 01 '13 at 10:27
  • I'm sorry, I can only answer questions on StackOverflow. It's not possible to provide training. – Christopher Painter Aug 01 '13 at 12:20
  • Think about the scope of the support you are asking for and the fact that you didn't even bother to upvote or accept my answer. I've given you the design for what you want, you need to go write it now. Regards, Chris – Christopher Painter Aug 01 '13 at 15:02
  • No, because for me, not English native, it's not a clear answer. But thanks anyway. Therefore, I will find the way. – Sonhja Aug 01 '13 at 15:32
  • And of course, I will upvote or accept it when I end up with a solution ;) – Sonhja Aug 01 '13 at 15:33
  • @Sonhja have you find the solution for this? I have the same problem, everything works perfectly but I need A previous version of your [ProductName] is installed. Do you want to uninstall it? [ Yes | No ] option. – grabhints Nov 11 '15 at 11:08
2

I found this post useful when solving the same problem. You can use the PREVIOUSVERSIONINSTALLED property you set in the upgrade-tag to open a custom dialog. Do this inside some UI-tags by adding the following code (when using the standard welcome dialog):

<Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="OldVersionDlg">PREVIOUSVERSIONSINSTALLED</Publish>
<Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="SetupTypeDlg">NOT Installed AND NOT PREVIOUSVERSIONSINSTALLED</Publish>

I based my own custom dialog on this Wix tutorial, and ended up with the following code:

 <Dialog Id="OldVersionDlg" Width="260" Height="85" Title="[ProductName] Setup" NoMinimize="yes">
        <Control Id="No" Type="PushButton" X="132" Y="57" Width="56" Height="17"
          Default="yes" Cancel="yes" Text="No">
          <Publish Event="EndDialog" Value="Exit">1</Publish>
        </Control>
        <Control Id="Yes" Type="PushButton" X="72" Y="57" Width="56" Height="17" Text="Yes">
          <Publish Event="EndDialog" Value="Return">1</Publish>
        </Control>
        <Control Id="Text" Type="Text" X="48" Y="15" Width="194" Height="30">
          <Text>A previous version of [ProductName] is currently installed. By continuing the installation this version will be uninstalled. Do you want to continue?</Text>
        </Control>
</Dialog>
Community
  • 1
  • 1
larsjr
  • 665
  • 7
  • 17
  • can you please give me more details about the first two lines of code from your post? Sorry for my English but I'm not sure i understand where to put: PREVIOUSVERSIONSINSTALLED – grabhints Nov 11 '15 at 09:48
  • The first two lines should be placed in a file describing the UI. I based mine on a sample called WixUI_InstallDir.wxs which is available from https://wix.codeplex.com/downloads/get/762939 under /src/ext/UiExtension/wxlib. The lines basically describes what should happen if the PREVIOUSVERSIONINSTALLED is set (in my case, open a custom dialog called OldVersionDlg). – larsjr Nov 12 '15 at 11:52
  • please see http://stackoverflow.com/questions/33690724/wix-custom-dialog-when-previous-version-exists – grabhints Nov 13 '15 at 10:52