WiX 3 driving me crazy - trying to create desktop shortcut
Asked Answered
A

5

25

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??

Amoretto answered 19/6, 2010 at 15:1 Comment(1)
this issue made me crazy also! and still crazing... because I need to make it work on Windows 7Conceptualism
F
20

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>
Fury answered 20/6, 2010 at 23:44 Comment(7)
OK, tanks for the sample - works for me on Win XP clients, but not on Win Server 2003 servers :-(Amoretto
hmm, that seems pretty weird. Suggest comparing 32/64bit? Roaming profiles or local? Does it work on the console but not remote desktop, etc?Fury
My Win2003 server is a 32-bit version, in a VMWare VM. Same for my WinXP test machine (also a VM). Anyway - since I need it only for XP for now, that solves my problem - thanks!Amoretto
With wix 3.6, when I try to set the shortcut Directory attribute to "DesktopFolder", I get "error LGHT0094: Unresolved reference to symbol 'Directory:DesktopFolder' in section 'Fragment:'". This is with a x64 build.Ray
NM, I forgot to expose the desktop folder in the directory hierarchy with <Directory Id="DesktopFolder"/>Ray
Do you really make a application named My application?Empathize
I don't understand why the Fragment is important, but it is. I tried not to define a Fragment, and that resulted in a desktop shortcut but no startmenu shortcut (I tested only in Windows 10).Isotron
M
11

This is based on @saschabeaumont's answer, but hopefully with some extra helpful hints for us WiX beginners (is it a nightmare for everybody to learn???).

First, create a fragment that contains the shortcut details itself:

<Fragment>
<Component Id="DesktopShortcut" Directory="INSTALLFOLDER" Guid="*">
    <RegistryValue Id="RegShortcutDesktop" 
            Root="HKCU" 
            Key="Software\Company\ApplicationName"
            Name="DesktopSC"
            Value="1" 
            Type="integer"
            KeyPath="yes" />

    <Shortcut Id="desktopSC" 
            Target="[INSTALLFOLDER]ApplicationName.exe"
            WorkingDirectory="INSTALLFOLDER"
            Icon="icon.ico"
            Directory="DesktopFolder" 
            Name="ApplicationName" 
            Advertise="no"/>
</Component>
</Fragment>

Next, note that this fragment will need including in the Product element, like this:

<Feature Id="ProductFeature" Title="Your Application Title" Level="1">
    ...
    <ComponentRef Id="DesktopShortcut" />
</Feature>

The ProductFeature will likely contain other fragments, such as files, and the program menu shortcut fragment.

Also, the DesktopFolder will need a reference in the TARGETDIR directory element (which will very likely contain other folders, such as ProgramMenuFolder as you require), like this:

<Directory Id="TARGETDIR" Name="SourceDir">
    ...
    <Directory Id="DesktopFolder" Name="Desktop"/>
</Directory>
Molehill answered 14/10, 2013 at 16:55 Comment(1)
What if you want the shortcut to be in All users profile?, setting ALLUSERS=1 and using HKLM for root in shortcut fails. ICE57Madore
P
7

Each of these ICE messages is basically complaining about the same thing: a component installing a shortcut should have a registry entry as its keypath. To fix this, add something like this to the component:

<RegistryValue Root="HKCU" Key="Software\MyCompany\MyApplicationName" 
    Name="desktopShortcut" Type="integer" Value="1" KeyPath="yes"/>

The same goes for the component installing the start menu shortcut. Take a look at the related wix documentation sample about creating a shortcut.

Perpetual answered 19/6, 2010 at 20:56 Comment(2)
Funny thing is: the app menu shortcut works flawlessly as is - no registry key stuff necessary. Just the desktop shortcut won't appear :-(Amoretto
It works fine on Win XP now, but keeps failing with Error 1909 - cannot create short cut link....... on Win Server 2003Amoretto
C
2

My purpose is to create an internet shortcut link and put to desktop. Here is the code that works for me:

<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
    <Product Id="09F1B63D-FB03-43FD-A326-FD49F93D00C8" Name="TestProduct" Language="1033" Version="0.0.0.1" Manufacturer="WixEdit" UpgradeCode="6B2F9AB4-73A6-45CB-9EC4-590D1AAA6779">
        <Package Description="Test file in a Product" Comments="Simple test" InstallerVersion="200" Compressed="yes" />
        <Media Id="1" Cabinet="simple.cab" EmbedCab="yes" />
        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="ProgramFilesFolder" Name="PFiles">
                <Directory Name="AAAA" Id="AAABBB">
                    <Component Id="AAAA">
                        <File Id="AAAA.EXE" Name="AAAA.exe" Source="U:\web\bin\x86\Release\AAAA.exe" />
                    </Component>
                </Directory>
            </Directory>
            <Directory Id="DesktopFolder">
                    <Component Id="StartMenuShortcuts" Guid="E8EDD7BC-9762-4C3D-8341-FAEC983D318A">
                        <RemoveFolder Id="ProgramMenuDir" On="uninstall" />
                        <RegistryValue Root="HKCU" Key="Software\[Manufacturer]\[ProductName]" Type="string" Value="" />
                        <util:InternetShortcut Id="WebsiteShortcut" Name="AAAA Website" Target="http://www.AAAA.com" />
                    </Component>
            </Directory>
        </Directory>
        <Feature Id="DefaultFeature" Title="Main Feature" Level="1">
            <ComponentRef Id="StartMenuShortcuts" />
            <ComponentRef Id="AAAA" />
        </Feature>
        <UI />
    </Product>
</Wix>

NOTE: you need to add the following to your candle and light command lines: -ext WiXUtilExtension

Conceptualism answered 5/12, 2011 at 8:2 Comment(0)
J
0

Not sure if this was available back in 2010, but this is how I do it in WiX 3.7:

<Directory Id="TARGETDIR" Name="SourceDir">
  <Directory Id="DesktopFolder" SourceName="Desktop" />
  <Directory Id="MergeRedirectFolder">
    <Component Id="MyExeComponent" Guid="{PUT-GUID-HERE}">
      <File Id="MyExeFile" Source="$(var.ExeSourcePath)" KeyPath="yes">
        <Shortcut
          Id="DesktopShortcut"
          Directory="DesktopFolder"
          Name="$(var.ShortcutName)"
          WorkingDirectory="MergeRedirectFolder" />
      </File>
    </Component>
  </Directory>
</Directory>
Jaggy answered 7/8, 2013 at 20:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.