Create shortcut to desktop using WiX

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


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>

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>

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>