Create shortcut to desktop using WiX

WixInstallationWindows InstallerShortcut

Wix Problem Overview


How do I create a shortcut on the desktop from a wix setup project?

Wix Solutions


Solution 1 - Wix

The shortcut is a non-advertised one, hope this helps someone. Remember to put the component in your feature tag.

<Directory Id="TARGETDIR" Name="SourceDir">
    <Directory Id="DesktopFolder" Name="Desktop">
        <Component Id="ApplicationShortcutDesktop" Guid="*">
            <Shortcut Id="ApplicationDesktopShortcut"
                Name="Text under your icon"
                Description="Comment field in your shortcut"
                Target="[MYAPPDIRPROPERTY]MyApp.exe"
                WorkingDirectory="MYAPPDIRPROPERTY"/>
            <RemoveFolder Id="DesktopFolder" On="uninstall"/>
            <RegistryValue
                Root="HKCU"
                Key="Software\MyCompany\MyApplicationName"
                Name="installed"
                Type="integer"
                Value="1"
                KeyPath="yes"/>
        </Component>
    </Directory>

    <Directory Id="ProgramFilesFolder" Name="PFiles">
        <Directory Id="MyCompany" Name="MyCompany">
            <Directory Id="MYAPPDIRPROPERTY" Name="MyAppName">
                <!-- main installation files -->
            </Directory>
        </Directory>
    </Directory>
</Directory>

Solution 2 - Wix

I think my way is easier, no need for you to create a registry key:

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

Solution 3 - Wix

Thanks for example. In WIX 3.8 it still raises: "Error 3 ICE43: Component ... has non-advertised shortcuts. It should use a registry key under HKCU as its KeyPath, not a file."

So I did this such way in a file with features:

   <Component Id="cmp79F6D61F01DD1060F418A05609A6DA70" 
              Directory="dirBin" Guid="*">
      <File Id="fil34B100315EFE9D878B5C2227CD1454E1" KeyPath="yes"
            Source="$(var.SourceDir)\FARMS.exe" >
        <Shortcut Id="DesktopShortcut"
                  Directory="DesktopFolder"
                  Name="FARMS $(var.FarmsVersion)"
                  Description="Local Land Services desktop application"
                  WorkingDirectory="INSTALLFOLDER"
                  Icon="FARMS.exe"
                  IconIndex="0"
                  Advertise="yes" >
           <Icon Id="FARMS.exe" SourceFile="$(var.SourceDir)\FARMS.exe" />
        </Shortcut>
        </File>
    </Component>

And mentioned desktop folder in a file with product definition:

  <Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="DesktopFolder" Name="Desktop" />

      <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLFOLDER" Name="FARMS" >
        </Directory>
      </Directory>
    </Directory>
  </Fragment>

Solution 4 - Wix

It seems lot easier in this [documentation][1].

First, you have to point your DesktopFolder,

   <Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="DesktopFolder" Name="Desktop"/>

Then you should create Shortcut component for file that you want to create shortcut of.

  <Component Id="PutYourComponentIdHere" Directory="FileDirectory" Guid="*">
    <File Id="NotYourComponentId" KeyPath="yes" Source="..\YourFileSource\YourExecutable.exe">
      <Shortcut Id="desktopServer" Directory="DesktopFolder" Name="YourShourtcutName" WorkingDirectory='WhereShouldYourShortcutPoint' Advertise="yes"/>
    </File>
  </Component>

It worked for me. I need to put icon but thats easy part. Hope it works. [1]: https://www.firegiant.com/wix/tutorial/getting-started/the-files-inside/

Solution 5 - Wix

After too much effort, I used this way:

<Product ...>
    <Feature Id="ProductFeature" Title="SetupProject" Level="1">
      ...
      ...
      <ComponentRef Id="cmpDesktopShortcut" />
    </Feature>

    <Component Id="cmpDesktopShortcut" Guid="PUT-GUID-HERE" Directory="DesktopFolder" >
        <Shortcut Id="MyDesktopShortcut" 
                  Name="Setup Project" 
                  Description="Opens the program." 
                  Directory="DesktopFolder" 
                  Target="[INSTALLFOLDER]App.exe"
                  WorkingDirectory="INSTALLFOLDER"/>
        <RegistryValue Root="HKCU" Key="Software\My Company\Sample Application" Name="installed" Type="integer" Value="1" KeyPath="yes" />
    </Component>
</Product>

Solution 6 - Wix

I believe that using a "Current User" (HKCU) registry key as Key Path causes problems on a multi-user machine tool. Because the registry key is only created for the current user and when a different user logs in, then the auto-repair of the installation kicks in.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRaymond HolmboeView Question on Stackoverflow
Solution 1 - WixRaymond HolmboeView Answer on Stackoverflow
Solution 2 - WixSean HallView Answer on Stackoverflow
Solution 3 - WixDimitryView Answer on Stackoverflow
Solution 4 - WixÖzgür AğcakayaView Answer on Stackoverflow
Solution 5 - WixMohsenView Answer on Stackoverflow
Solution 6 - WixDirkscheView Answer on Stackoverflow