WiX 3 driving me crazy – trying to create desktop shortcut

desktop-shortcutwixwix3

I have an app that is being installed with WiX 3 – most of the install works fine by now, but trying to get the desktop shortcut to work seems to cost me my mind…

I have my app being installed and I already have a shortcut on the Start Menu folder – works just fine. But how do I get the desktop shortcut up and running?

<Product Id="*" Name="....." UpgradeCode="MY-GUID">
  <Package Id="*" InstallerVersion="200" Compressed="yes" />
    <Media Id="1" Cabinet="foobar.cab" EmbedCab="yes" />
    <Property Id="ALLUSERS">1</Property>

    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramMenuFolder">
        <Directory Id="ApplicationProgramsFolder" Name="FooBar"/>
      </Directory>
      <Directory Id="DesktopFolder"  SourceName="Desktop"/>
      <Directory Id="ProgramFilesFolder">
         <Directory Id="FoobarDir" Name="FOOBAR">
            <Directory Id="INSTALLLOCATION" Name="FooApp">
              <Component Id="MainFiles" Guid=".....">
                <File Id="FooMainApp" Source="FooMainApp.exe" />
              </Component>
            </Directory>
         </Directory>
      </Directory>
    </Directory>
    ....
    <!-- this shortcut here works just fine ... -->
    <DirectoryRef Id="ApplicationProgramsFolder">
      <Component Id="AppShortcut" Guid="...">
         <Shortcut Id="ApplicationStartMenuShortcut"
                   Name="FooBarApp" Description="..."
                   Target="[INSTALLLOCATION]FooMainApp.exe"
                   WorkingDirectory="INSTALLLOCATION"/>
      </Component>
    </DirectoryRef>
    <!-- but this shortcut here never seems to work .. ... -->
    <DirectoryRef Id="DesktopFolder">
       <Component Id="DesktopShortcut" Guid="....." >
          <Shortcut Id="DesktopAppShortcut"
                    Advertise="no"
                    Name="FooBarApp"  Description="...."
                    Target="[INSTALLLOCATION]FooMainApp.exe"
                    WorkingDirectory="INSTALLLOCATION"/>
       </Component>
    </DirectoryRef>

The errors I keep getting are:

ICE18: KeyPath for Component:
'DesktopShortcut' is Directory:
'DesktopFolder'. The
Directory/Component pair must be
listed in the CreateFolders table.
ICE38: Component DesktopShortcut
installs to user profile. It must use
a registry key under HKCU as its
KeyPath, not a file.
ICE43: Component
DesktopShortcut has non-advertised
shortcuts. It should use a registry
key under HKCU as its KeyPath, not a
file.

I do not understand what on earth WiX 3 / Windows Installer is trying to tell me here…. anyone??

Both components, AppShortcut and DesktopShortcut, are in fact part of the "main" feature – I don't see any issue there. I can't figure out what on earth could be wrong here….

Update: ok, so I added some registry key stuff to my desktop shortcut

<Component Id="DesktopShortcut" Guid="BF3587B4-F52E-411E-8814-CFCBF8201C0D">
    <RegistryKey Root="HKCU" Key="Software\Foo Inc\FooBarApp\Installed" 
                 Action="createAndRemoveOnUninstall">
       <RegistryValue Name="DTSC" Value="1" Type="integer" KeyPath="yes"/>
    </RegistryKey>
    <Shortcut Id="DesktopShortcut" Directory="DesktopFolder"
              Name="FooBar" WorkingDirectory="INSTALLLOCATION"
              Icon="foobar.ico" 
              Target="[INSTALLOCATION]FooMainApp.exe"/>
</Component>

now the ICE messages are gone, but when I try to install the app, I get Error 1909 – the target folder doesn't exist, or you do not have permission to write to it (or something like that)

Update 2: the above sample code provided does work on Win XP, but it keeps failing on Win Server 2003 🙁 Any further ideas??

Best Answer

Here's a working example from our live production code...

<Fragment>
    <Component Id="DesktopShortcut" Directory="APPLICATIONFOLDER" Guid="*">
        <RegistryValue Id="RegShortcutDesktop" Root="HKCU" 
                Key="SOFTWARE\ACME\settings" Name="DesktopSC" Value="1" 
                Type="integer" KeyPath="yes" />
        <Shortcut Id="desktopSC" Target="[APPLICATIONFOLDER]MyApp.exe"
                Directory="DesktopFolder" Name="My Application" 
                Icon="$(var.product).ico" IconIndex="0"
                WorkingDirectory="APPLICATIONFOLDER" Advertise="no"/>
    </Component>
</Fragment>