Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WiX 3 driving me crazy - trying to create desktop shortcut

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

like image 621
marc_s Avatar asked Jun 19 '10 15:06

marc_s


4 Answers

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>
like image 112
saschabeaumont Avatar answered Nov 17 '22 03:11

saschabeaumont


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>
like image 40
noelicus Avatar answered Nov 17 '22 01:11

noelicus


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.

like image 27
Wim Coenen Avatar answered Nov 17 '22 03:11

Wim Coenen


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

like image 2
Mason Zhang Avatar answered Nov 17 '22 02:11

Mason Zhang