IT:AD:WiX:HowTo:Create an Uninstall Shorcut
Summary
Process
After defining some precompiler variables as follows:
<!-- ex: SomeCompany.SomeDiv.SomeAppName --> <?define PRODUCTTARGETNAME = "$(var.ConsoleApplication1.TargetName)"?> <!-- ex: http://somecompany.com/products/$(var.PRODUCTTARGETNAME) --> <?define PRODUCT_INFO_URL = "http://somecompany.com/products/$(var.PRODUCTTARGETNAME)"?> <!-- ex: c:\Workspace\SolutionDir\ProjectDir\SomeCompany.SomeDiv.SomeAppName.exe --> <?define PRODUCTTARGETPATH = "$(var.ConsoleApplication1.TargetPath)"?> <!-- ex: c:\Workspace\SolutionDir\ProjectDir\ --> <?define PRODUCTTARGETDIR = "$(var.ConsoleApplication1.TargetDir)"?> <!-- ex: SomeCompany.SomDiv.SomeAppName.exe --> <?define PRODUCTTARGETFILENAME = "$(var.ConsoleApplication1.TargetFileName)"?> <!-- ex: 1.x --> <?define PRODUCTVERSION_X = "1.x"?>
and a directory structure along the following lines (under the Well-Known ProgramMenuFolder to make the shortcut easily findable):
<!-- STEP: Define Program Menu Folders -->
<Directory Id="ProgramMenuFolder">
<Directory Id="_directory_ProgramMenuFolder_Manufacturer" Name="$(var.PRODUCTMANUFACTURER)">
<Directory Id="_directory_ProgramMenuFolder_Product" Name="$(var.PRODUCTTARGETNAME)">
<Directory Id="_directory_ProgramMenuFolder_Version" Name="$(var.PRODUCTVERSION_X)">
<Directory Id="_directory_ProgramMenuFolder_Uninstall" Name="Uninstall"/>
</Directory>
</Directory>
</Directory>
</Directory>
One can create a Component that contains a shortcut back to the MSI to uninstall:
<?xml version="1.0" encoding="utf-8"?>
<Include>
<!---
Notes:
This shortcut is created under the Start/programMenu
to make it easy to find later.
Note that it has its own subdirectory.
Requires:
PreCompiler vars need to be set up first:
PRODUCTMANUFACTURER
PRODUCTTARGETNAME
PRODUCTVERSION_X
PRODUCTTARGETFILENAME
References:
http://bit.ly/gOUmuW
http://bit.ly/fAgocz
-->
<Component Id="_componentClientConsoleUninstall" Guid="*">
<!-- Every Component requires an element that can be the KeyPath.
Shortcuts (which cannot be a Component's KeyPath)
in Components that have no File (that can be a KeyPath),
require a Registry (of any value) as a workaround -->
<RegistryValue Root="HKCU"
Key="Software\$(var.PRODUCTMANUFACTURER)\$(var.PRODUCTTARGETNAME)\$(var.PRODUCTVERSION_X)\Shortcuts\Uninstall"
Name="installed"
Type="integer"
Value="1"
KeyPath="yes" />
<!-- Directory:
Uninstall shortcut could be in in the INSTALLDIR
with the main app, but I prefer it tucked away
in its own sub subdirectory -->
<Shortcut Id="_Shortcut_uninstall"
Name="Uninstall $(var.PRODUCTTARGETNAME)"
Directory="_directory_ProgramMenuFolder_Uninstall"
Target="[SystemFolder]msiexec.exe"
Arguments="/x [ProductCode]"
Description="Uninstalls $(var.PRODUCTTARGETFILENAME)" />
<RemoveFolder Id="_removeClientConsoleUninstallFolder" On="uninstall"/>
</Component>
</Include>
Note the reference to /x [ProductCode] which I suspect will be the Guid on the Product element.