Wix create non advertised shortcut for all users / per machine
Asked Answered
L

3

89

In WIX, how do you create a non advertised shortcut in the allusers profile? So far I've only been able to accomplish this with advertised shortcuts. I prefer non-advertised shortcuts because you can go to the shortcut's properties and use "find target".

In the tutorials I've seen use a registry value for the keypath of a shortcut. The problem is they use HKCU as the root. When HKCU is used, and another user uninstalls the program (since it's installed for all users) the registry key is left behind. When I use HKMU as the root I get an ICE57 error, but the key is removed when another user uninstalls the program. I seem to be pushed towards using HKCU though HKMU seems to behave correctly (per-user vs all-users).

When I try to create the non advertised shortcut I get various ICE error such as ICE38, ICE43, or ICE 57. Most articles I've seen recommend "just ignore the ice errors". There must be a way to create the non advertised shortcuts, without creating ICE errors.

Please post sample code for a working example.

Letterhead answered 13/1, 2010 at 16:12 Comment(0)
L
117

Sorry if it's bad etiquette to answer my own question.

Recently I stumbled upon the information on DISABLEADVTSHORTCUTS property. I created an install with advertised shortcuts and set the DISABLEADVTSHORTCUTS property to 1 which produced non-advertised shortcuts. This bypasses ICE43 errors because an advertised shortcut can use a file as a keypath. Because DISABLEADVTSHORTCUTS has been set Windows Installer will replace these advertised shortcuts with regular shortcuts.

I set the Package Element's InstallScope attribute to "perMachine". This sets the ALLUSERS property to 1. The values of ProgramMenuFolder and DesktopFolder will then resolve to the All Users profile.

For folders created under ProgramMenuFolder there is a RemoveFolder and RegistryValue element. The examples I've seen (ex1, ex2) use HKCU as the root for the RegistryValue. I changed this root to HKMU which resolves to HKCU or HKLM depending on the value of ALLUSERS.

In short, with DISABLEADVTSHORTCUTS set to 1 your advertised shortcuts will not produce ICE errors, but will be converted to non-advertised shortcuts when installed. A RegistryValue with root HKMU is fine for a KeyPath as long as it's not keypath for a non-advertised shortcut.

<?xml version="1.0" encoding="utf-8"?>
<!-- This example is based on SampleFirst by Gábor DEÁK JAHN, Tramontána:
        http://www.tramontana.co.hu/wix/lesson1.php#1.3
    Original SampleFirst:
        http://www.tramontana.co.hu/wix/download.php?file=samples/samplefirst.zip&type=application/zip -->
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Name="Foobar 1.0" Id="YOURGUID-21F1-4026-ABD2-7CC7F8CE4D18" UpgradeCode="YOURGUID-AFA4-46C6-94AA-EEE3D104F903" Language="1033" Codepage="1252" Version="1.0.0" Manufacturer="Acme Ltd.">
        <Package Id="*" Keywords="Installer" Description="Acme's Foobar 1.0 Installer" Comments="Foobar is a registered trademark of Acme Ltd." Manufacturer="Acme Ltd." InstallerVersion="100" Languages="1033" Compressed="yes" SummaryCodepage="1252" InstallScope="perMachine" />
        <Media Id="1" Cabinet="Sample.cab" EmbedCab="yes" DiskPrompt="CD-ROM #1" />
        <Property Id="DiskPrompt" Value="Acme's Foobar 1.0 Installation [1]" />
        <Property Id="DISABLEADVTSHORTCUTS" Value="1" />
        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="ProgramFilesFolder" Name="PFiles">
                <Directory Id="Acme" Name="Acme">
                    <Directory Id="INSTALLDIR" Name="Foobar 1.0">
                        <Component Id="MainExecutable" Guid="YOURGUID-3E4F-47A2-86F1-F3162E9C4798">
                            <File Id="FoobarEXE" Name="FoobarAppl10.exe" DiskId="1" Source="FoobarAppl10.exe" KeyPath="yes">
                                <Shortcut Id="startmenuFoobar10" Directory="ProgramMenuDir" Name="Foobar 1.0" WorkingDirectory="INSTALLDIR" Icon="Foobar10.exe" IconIndex="0" Advertise="yes" />
                                <Shortcut Id="desktopFoobar10" Directory="DesktopFolder" Name="Foobar 1.0" WorkingDirectory="INSTALLDIR" Icon="Foobar10.exe" IconIndex="0" Advertise="yes" />
                            </File>
                        </Component>
                        <Component Id="HelperLibrary" Guid="YOURGUID-C7DA-4C02-A2F0-A6E089FC0CF3">
                            <File Id="HelperDLL" Name="Helper.dll" DiskId="1" Source="Helper.dll" KeyPath="yes" />
                        </Component>
                        <Component Id="Manual" Guid="YOURGUID-FF92-4BF4-A322-819A3B2265A0">
                            <File Id="Manual" Name="Manual.pdf" DiskId="1" Source="Manual.pdf" KeyPath="yes">
                                <Shortcut Id="startmenuManual" Directory="ProgramMenuDir" Name="Instruction Manual" Advertise="yes" />
                            </File>
                        </Component>
                    </Directory>
                </Directory>
            </Directory>
            <Directory Id="ProgramMenuFolder" Name="Programs">
                <Directory Id="ProgramMenuDir" Name="Foobar 1.0">
                    <Component Id="ProgramMenuDir" Guid="YOURGUID-D1C2-4D76-BA46-C6FA79862E77">
                        <RemoveFolder Id="ProgramMenuDir" On="uninstall" />
                        <RegistryValue Root="HKMU" Key="Software\[Manufacturer]\[ProductName]" Type="string" Value="" KeyPath="yes" />
                    </Component>
                </Directory>
            </Directory>
            <Directory Id="DesktopFolder" Name="Desktop" />
        </Directory>
        <Feature Id="Complete" Level="1">
            <ComponentRef Id="MainExecutable" />
            <ComponentRef Id="HelperLibrary" />
            <ComponentRef Id="Manual" />
            <ComponentRef Id="ProgramMenuDir" />
        </Feature>
        <Icon Id="Foobar10.exe" SourceFile="FoobarAppl10.exe" />
    </Product>
</Wix>
Letterhead answered 29/9, 2010 at 19:3 Comment(8)
Really nice job with the details in your answer. I found this extremely helpful as I have been wading through the WiX documentation and samples. Thanks!Seraglio
Great answer. But suppose I have a desktop shortcut in a separate component (because I install it conditionally). IIUC such shortcuts cannot be advertised. If I try to add Advertise="yes" even with DISABLEADVTSHORTCUTS I get error CNDL0035. Can you see a way to make such shortcut with HKMU registry key?Aretha
Answering your own question is not bad etiquette at all if you've found a good solution, and I'm very grateful you did - and with an excellent answer to boot. +1!Diba
Don't reference icon to executable file. Icons are copied in special directory (Windows\Installer\{GUID}), and shortcut will use icon from this location (i.e. not from executable in INSTALLDIR), so it is better to use separate icon file.Nausea
Thank You So Much. I spent hours troubleshooting this. Had no clue about DISABLEADVTSHORTCUTS.Tucky
So basically "tricking" the compiler into thinking it's advertised and then subverting it with a public property. Clever.Hidalgo
@DmitryAzaraev You may want to reference a stack overflow question for the icon. It is not easy. When I had an Icon element with Id="LogoIcon", it gave an error that my extension of my icon did not match the extension of my KeyFile (which is .exe). I tried referencing the executable several ways and then changed the ID of the icon element to Id="LogoIcon.exe" and it finally works. That makes no sense.Ephemeron
@Ephemeron I stumpled across that oddity too, just with a .ico file needing a .ico id.Dich
C
10

Although this post is rather old it contains quite useful info and looks still active. I want to point out that in general you do NOT need a dummy registry key for your shortcut! AFAIK this is WiX tutorial thingy and is not MSI or certification requirement. Here is an example with no reg key:

<Fragment Id="Folders">
  <Directory Id="TARGETDIR" Name="SourceDir">
    <Directory Id="ProgramFilesFolder">
      <Directory Id="INSTALLFOLDER" Name="MyApp">
      </Directory>
    </Directory>
    <Directory Id="ProgramMenuFolder">
      <Directory Id="MyAppStartMenuDir" Name="MyApp"/>
    </Directory>
  </Directory>
</Fragment>
<Fragment Id="Components">
  <Component Id="MyAppComp" Directory="INSTALLFOLDER" ...>
    <!--The advertise flag below is to bypass ICE errors in WiX, the actual shortcut will not be advertises if those are disabled globally with DISABLEADVTSHORTCUTS-->
    <File ..." KeyPath="yes">
      <Shortcut Id="MyAppStartMenuLink" Directory="MyAppStartMenuDir" Advertise="yes" ... />
    </File>
    <RemoveFolder Id="StartMenuDirRemoved" Directory="MyAppStartMenuDir" On="uninstall" />
  </Component>
</Fragment>

Note that this will put your shortcut together with the executable in one component. If this bothers you then use dummy registry key (as in the very well explained accepted self answer).

Covarrubias answered 25/2, 2015 at 1:28 Comment(2)
Remember to add <Property Id="DISABLEADVTSHORTCUTS" Value="1" /> to the Product elementIreneirenic
@Ireneirenic this should be added to the answer. Without it it doesn't work.Criss
B
2

Take a look at From MSI to WiX, Part 10 - Shortcuts by Alex Shevchuk.

Or Rob Menching's blog post How to create an uninstall shortcut (and pass all the ICE validation).

Basically ICE57 is rather annoying... but here's the (seems to be working) code I'm using for Desktop shortcuts :)

<Component Id="DesktopShortcut" Directory="APPLICATIONFOLDER" Guid="*">
    <RegistryValue Id="RegShortcutDesktop" Root="HKCU" Key="SOFTWARE\My App\1.0\settings" Name="DesktopSC" Value="1" Type="integer" KeyPath="yes" />
    <Shortcut Id="desktopSc" Target="[APPLICATIONFOLDER]MyApp.exe" Directory="DesktopFolder" Name="My Applications" Icon="myapp.ico" IconIndex="0" WorkingDirectory="APPLICATIONFOLDER" Advertise="no"/>
    <RemoveFolder Id="RemoveShortcutFolder" On="uninstall" />
    <Condition>DT_SHORTCUT=1</Condition>
</Component>
Benedictbenedicta answered 1/3, 2010 at 22:21 Comment(2)
Your example uses "HKCU" as the keypath. If one user installs the app, and another user removes the app the registry key will remain behind. The first link posted uses HKCU for the registry key. The second uses a file as the keypath which produces ICE43 and ICE57 errors.Letterhead
The registry key, yes. Not the shortcut itself however :)Benedictbenedicta

© 2022 - 2024 — McMap. All rights reserved.