A while ago, I saw this blog post about creating an uninstall shortcut using the WiX toolset. My first reaction was, "Uhh, I thought the Logo says you're not supposed to create uninstall shortcuts." But as the blog author noted clients are clients (especially if they are paying the bills). My second reaction to the blog entry was, "Jeez, those CustomActions don't seem like they should be necessary."
Well, it turned out that I've been doing a lot of demos recently. When creating the demo code, I found that having an uninstall shortcut installed turned out to be really handy. I routinely forget to uninstall the application package during my demos (which often messes up later demos) and the shortcut serves as a very handy reminder to clean up after myself. Saves me from click over to Add/Remove Programs (ARP) as well.
Anyway, since I blogged a bunch of random personal goo tonight, I thought I'd wrap up by sharing my solution for creating an uninstall shortcut without using any CustomActions.
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="PUT-GUID-HERE"
UpgradeCode="PUT-GUID-HERE"
Name="TestUinstallShortcut"
Language="1033"
Version="1.0.0"
Manufacturer="Microsoft Corporation"><Package InstallerVersion="200"
Compressed="yes" /><Media Id="1" />
<Directory Id="TARGETDIR"
Name="SourceDir">
<Directory Id="ProgramMenuFolder">
<Directory Id="ShortcutFolder"
Name="My Application">
<Component Id="UninstallShortcutComponent"
Guid="PUT-GUID-HERE">
<RegistryKey Root="HKCU"
Key="Software\My Application\Uninstall">
<RegistryValue Value="RobMen Was Here."
Type="string"
KeyPath="yes" />
</RegistryKey><Shortcut Id="UninstallProduct"
Name="Uninstall My Application"
Target="[System64Folder]msiexec.exe"
Arguments="/x [ProductCode]"
Directory="ShortcutFolder"
Description="Uninstalls My Application" /><RemoveFolder Id="RemoveShorcutFolder"
On="uninstall" />
</Component>
</Directory>
</Directory>
</Directory><Feature Id="TestUninstallShortcut"
Title="Test Uninstall Shortcut Feature"
Level="1">
<ComponentRef Id="UninstallShortcutComponent" />
</Feature>
</Product>
</Wix>
The only interesting part in this example is inside the Component element. In there are actually a few interesting things to notice:
1. As noted on the other blog entry, the registry key is created to make ICE18, ICE38 and ICE48 happy. I know the registry key is recommended to make things work correctly for roaming user profiles (how many people use that? I don't know) but I don't understand why the ICEs aren't comfortable with me using the ShortcutFolder as the keypath (it is in the user's profile and should be just as good as the registry key as the key path). I believe it has something to some minutia in the way that Group Policy and the Windows Installer interact.
2. The Shortcut/@Target uses the System64Folder standard directory as the root for msiexec.exe. I use System64Folder because that always resolves to the native "system32" directory on the operating system (SystemFolder resolves to the "SysWow64" directory on 64-bit operating systems). Now, I'm not a 64-bit guru and I don't have access to a 64-bit OS right now so I could be wrong about System64Folder but my instincts say this is the right thing. It works on 32-bit XP, I tested. <smile?>
Note: I use the "[PropertyFolder]executable.exe" syntax here because I did not install the msiexec.exe (obviously, since that's the Windows Installer itself). If the shortcut pointed at a file I installed then I would have used the "[#FileId]" syntax instead.
3. The Shortcut/@Arguments passes the "uninstall command" (/x) plus the standard property for the product code of the package. This is much simpler solution that proposed in the other blog entry.
4. The Remove folder element exists to make ICE64 happy. Like the registry key listed above, this cleans up things in a roaming user scenario. I wish these quirky behaviors weren't exposed to package developers and that the Windows Installer would just "do the right thing". There must be some crazy scenarios where the Windows Installer can't figure out things for itself.
Anyway, that's about the simplest .wxs file that I can think of to create an MSI that installs an shortcut to uninstall itself.
Silly? Yes.
Helpful? Hopefully. You should be able to use this information as a starting place to install shortcuts that point at more useful things (like your own application).
More complicated than it should be? Definitely. The ICEs add a registry key and remove folder entry that I don't want/need. I'm considering adding some syntactic sugar to the WiX schema to simplify the authoring in this case but I'm concerned about creating a registry key unexpectedly. Or maybe we can just convince the Windows Installer team to change the requirements that make these ICEs necessary.
In the mean time, keep coding, you know I am.
RobMensching.com LLC
9 Comments
Comment by Christopher Painter on Friday, April 27, 2007 6:22 AM
Comment by Alex Henderson on Friday, April 27, 2007 5:09 PM
Keep up the good work!
Comment by B2Pi on Monday, May 21, 2007 8:21 PM
So... How can we convince the Windows Installer team that this is pointless?
Comment by sekaran on Friday, August 24, 2007 9:29 AM
i have create exe and build set up file .
but i could not create uninsatll exe.how to create uninstall exe .
Comment by Larry on Thursday, May 1, 2008 8:39 PM
<RemoveFolder Id="RemoveShorcutFolder"
is a typo for
<RemoveFolder Id="ShortcutFolder"
Comment by Arun on Monday, November 3, 2008 6:06 AM
1. HKCU will be installed for every user using one of the advertised shortcuts.
2. Uninstall shortcut will not removed when more than one version of the product is installed, as it is non-advertised shortcut.
Any Ideas on these issues. And thanks for the excellent blog, seems to be this is the only source on shortcuts.
Comment by Zachary Young on Friday, February 13, 2009 11:21 AM
Comment by Louis on Tuesday, May 4, 2010 3:51 PM
But I like to know more. :) Is there any way to custumize the title and message of the window after one clicks the shortcut? Alternatively Showing the repair & uninstall dialog would be even nicer.
Comment by Christoph on Monday, April 4, 2011 11:58 PM
i just started to program WIX. How can i delete a Folder, for example directx, during the installation. I don´t want to use "cmd". Is there a way?
Tank you, Christoph