Uninstall Shortcuts |
People like uninstall shortcuts as it makes it easier to uninstall a product however Microsoft want users to use the Add/Remove Applet instead.
As I've been asked how to create these in the past and then I saw this blog entry I decided to improve on my previous example while creating a reusable "command".
The following shows how the uninstall shortcut macro (defined below) can be called. The code is included in the "TryMeShortcuts.MM" sample that MAKEMSI installed. Note that the directory key for the shortcut location is passed:
<$UninstallShortcut SCDIR="MY_SHORTCUT_FOLDER" Icon="@.\TryMe.ico"> ;<$UninstallShortcut SCDIR="MY_SHORTCUT_FOLDER" Icon="@.\TryMe.ico" Maint='N' Args="/qb"> ;;Direct Uninstall, Don't confirm (NOT recommended)
The following defined the macro the above example uses, this should be placed into a common header file:
#( ;--- Note that MS don't like, they want you to go via Add-Remove Applet --- #define UninstallShortcut ;;Version 07.119 ;--- Make PER-MACHINE (practical) or PER-USER (keep MS happy) component? --- #if ['{$LOGO=^N^ $$UPPER}' = 'Y'] ;--- Create PER-USER component (For LOGO, keep Microsoft happy) ----- #define+ @@CU Y #define+ @@LM N #elseif ;--- Create PER-MACHINE component (less annoying for multiple users) --- #define+ @@CU N #define+ @@LM Y #endif ;--- Direct Uninstall or Maintenance Dialog (preferred & default)? ------ #if ['{$Maint=^Y^ $$UPPER}' = 'N'] ;--- Direct Uninstall (no repair options etc) ----------------------- #define+ @@What Uninstall #define+ @@WhatSwitch /x #elseif ;--- The Default, use maintenance dialog (can choose remove) -------- #define+ @@What Maintain #define+ @@WhatSwitch /i #endif ;--- Define the component ----------------------------------------------- <$Component "UninstallShortcut" Create="Y" Directory_="<$AnyDir>" LM="<$@@LM>" CU="<$@@CU>"> ;--- Create shortcut (unfortunately ICE lac of smarts will interpret as PER-USER) --- #( <$Shortcut Dir="[{$SCDIR}]" Title=^{$Title=~<$@@What> <$ProdInfo.ProductName>~}^ Icon="{$Icon=^.\<$@@What>Shortcut.ico^}" Target="[System64Folder]msiexec.exe" ;;Windows Installer EXE Arguments=^<$@@WhatSwitch> [ProductCode] {$Args=''}^ ;;Maint/Uninstall switch and product code (plus possible extra user parms) Description=^{$ToolTip=~<$@@What>s <$ProdInfo.ProductName> version <$ProductVersion>~}^ > #) ;--- No need to ignore ICE messages if creating as per LOGO requirements --- #if ['{$LOGO $$UPPER}' <> 'Y'] ;--- Installed PER-MACHINE, Stop the whinging... ---------------- <$MsiValFilter "Component UninstallShortcut has non-advertised shortcuts. It's KeyPath registry key should fall under HKCU" Comment=^Not true, this MSI installs per-machine^> <$MsiValFilter "Component 'UninstallShortcut' has both per-user and per-machine data with a per-machine KeyPath" Comment=^Not true, this MSI installs per-machine^> #endif <$/Component> #)