Pattern to do a wix upgrade without messing with the desktop icons of the users

The Wix setup I'm working on asks the user whether to install a shorcut from the main program on the desktop.

The problem is that during upgrades, the shortcut is removed and then recreated :

Is there a simple way to properly handle this situation ?

Below are informations on my wix setup :

Install is per machine

The users chooses to install the desktop shortcut via a checkbox that is added on a modified version of the "Choose destination" :

<Control Id="DesktopShortcutCheckBox" Type="CheckBox" X="20" Y="160" Width="290" Height="17" Property="INSTALLDESKTOPSHORTCUT" CheckBoxValue="[INSTALLDESKTOPSHORTCUT]" Text="!(loc.InstallDirDlgCreateDesktopShortcut)" />

In the UI tag I have the property initialized :

<Property Id="INSTALLDESKTOPSHORTCUT" Value="1"/>

This is the component to create the shortcut with the INSTALLDESKTOPSHORTCUT condition :

<Directory Id="DesktopFolder" Name="Desktop">
    <Component Id="desktopconnecteurdts" Guid="a-real-guid-here">
        <Condition>INSTALLDESKTOPSHORTCUT=1</Condition>
        <Shortcut Id="desktopconnecteurdts" Name="DTS eXplorer" WorkingDirectory="ApplicationFolder" Icon="DTSeXplorer.exe" Target="[ApplicationFolder]\DTSeXplorer.exe" Advertise="no" />
    </Component>
</Directory>

Upon launch the setup will check if an older version exists and remove the older version if found :

<Upgrade Id="$(var.UpgradeCode)">
    <UpgradeVersion OnlyDetect="no"
                    Property="PREVIOUSVERSIONSINSTALLED"
                    Minimum="$(var.OldProductVersion)"
                    IncludeMinimum="yes"
                    Maximum="$(var.ProductVersion)"
                    IncludeMaximum="no" 
                    RemoveFeatures="all" />
    <UpgradeVersion OnlyDetect="yes" Property="PROJECT_DOWNGRADE"
                    Minimum="$(var.ProductVersion)" IncludeMinimum="no" />
</Upgrade>

The product version major does not change, for example I'm upgrading from 1.6.8.12345 to 1.7.2.56789

Thanks !

Upvotes: 5

Views: 612

Answers (2)

shriek
shriek

Reputation: 5197

You can save and restore the setting for the shortcut using only wix.

Your property has to look like this.

<Property Id="INSTALLDESKTOPSHORTCUT" Value="1" Secure="yes">
  <RegistrySearch Id="Reg64" Root="HKLM" Win64="yes" Key="Software\$(var.ProductCompany)" Name="CreateDesktopShortcut" Type="raw"></RegistrySearch>
  <RegistrySearch Id="Reg32" Root="HKLM" Win64="no" Key="Software\$(var.ProductCompany)" Name="CreateDesktopShortcut" Type="raw"></RegistrySearch>
</Property>

The two 'RegistrySearch's are only there to cover both 32bit and 64bit installer, if you only use 32bit you can remove one of them.

And under your root folder add this.

<Component Permanent="yes" Id="RegistryEntries" Guid="YOUR_GUID">
  <RegistryKey Root="HKLM" Key="Software\$(var.ProductCompany)" Action="create">
    <RegistryValue Type="integer" Name="CreateDesktopShortcut" Value="[INSTALLDESKTOPSHORTCUT]" />
  </RegistryKey>
</Component>

Upvotes: 0

BryanJ
BryanJ

Reputation: 8563

Write the value of INSTALLDESKTOPSHORTCUT to the registry during installation. Whenever your installer starts, you can read the registry and if that key exists, set it as the default value of that property.

Not sure if you can do anything about the location of the shortcut on the desktop however.

Upvotes: 1

Related Questions