Create shortcut to desktop using WiX

So I have this setup project in Wix and wanted to have a shortcut on the desktop. This must be easy you might think. But that is not the case. All the code snippets found on the Internet did not work. After a few hours of struggling and reading the documentation I finally got it right, so I am sharing it with you here.


The shortcut is a non-advertised one, hope this helps someone. Remember the 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"
            <RemoveFolder Id="DesktopFolder" On="uninstall"/>

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

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">
          WorkingDirectory="MergeRedirectFolder" />

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"
                  Name="FARMS $(var.FarmsVersion)"
                  Description="Local Land Services desktop application"
                  Advertise="yes" >
           <Icon Id="FARMS.exe" SourceFile="$(var.SourceDir)\FARMS.exe" />

And mentioned desktop folder in a file with product definition:

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

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

It seems lot easier in this documentation.

First, you have to point your DesktopFolder,

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

It worked for me. I need to put icon but thats easy part. Hope it works.

After too much effort, I used this way:

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

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

Need Your Help

Where does the k prefix for constants come from?

c++ objective-c c prefix hungarian-notation

it's a pretty common practice that constants are prefixed with k (e.g. k_pi). But what does the k mean?

Countdown timer using Moment js

javascript jquery countdown unix-timestamp momentjs

I am making a countdown timer for an event page, i used moment js for this.