How do I create a shortcut on the desktop from a wix setup project?
6 Answers
The shortcut is a non-advertised one. 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>

- 20,030
- 7
- 43
- 238

- 2,061
- 1
- 16
- 18
-
You need backward slashes on your Registry Key – Stealth Rabbi May 14 '13 at 19:36
-
6what's the registry value for? – BatteryBackupUnit Jun 17 '15 at 11:59
-
2@BatteryBackupUnit A shortcut cannot be a key path for a component, so the registry value serves that purpose. The same technique is used in the WiX documentation: http://wixtoolset.org/documentation/manual/v3/howtos/files_and_registry/create_start_menu_shortcut.html – vangelion Jul 24 '15 at 21:10
-
3It's better to put the file id for the Target property instead of "[MYAPPDIRPROPERTY]MyApp.exe". – Hossein Shahdoost Oct 30 '15 at 09:45
-
Missing Shortcut !! Can you help me with the [MYAPPDIRPROPERTY] ? – Abdulsalam Elsharif Apr 16 '16 at 21:59
-
6I had to add this under feature tag:
– uriel Jun 07 '16 at 10:23 -
@HosseinShahdoost Using a file ID for Target fails ICE69, since the shortcut and file are in different components. They can't be in the same component because the shortcut is per user, but the component may be per machine. – Edward Brey May 15 '18 at 19:17
-
1@SteinÅsmul if they use Guid="*" it can cause problems in future upgrades and uninstalls as it enables the possibility of two component guids pointing to the same file location. I'd always push {PUT-GUID-HERE} to prevent future headaches. See this guy: https://stackoverflow.com/questions/43062435/msi-fixing-different-component-guids-for-the-same-file – user922020 Oct 17 '18 at 16:28
-
No, it is the opposite - and this I am actually sure of. Using `Guid="*"` - or [just leaving out the whole attribute as described here](https://stackoverflow.com/a/24769965/129130) - enables automatic component GUIDs that are calculated from the component key path making them stable across releases. The problem occurs for people who generate a new component GUID manually and keep the file install location OR move the component to a different folder **without** creating a new component GUID. [This component GUID complexity is explained here](https://stackoverflow.com/a/1422121/129130). – Stein Åsmul Oct 17 '18 at 17:06
-
1Works great. But I was getting error that `ApplicationShortcutDesktop` is not part on any feature. So don't forget to add `
` in `Feature` tag – Riz Apr 19 '19 at 07:49 -
This helped but I can't get it to work when using InstallScope='perMachine'. Don't know why Wix has made shortcut creation so painful. It's a very common task for an installer. – AriesConnolly Aug 05 '22 at 00:17
-
What is the correct way to do it for InstallScope="perMachine"? Is it ok to use HKLM? – andrebroz Sep 14 '22 at 11:34
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>

- 7,629
- 2
- 29
- 44
-
2From [documentation](http://wixtoolset.org/documentation/manual/v3/howtos/files_and_registry/create_start_menu_shortcut.html) regarding the registry key: _"This is required as a Shortcut cannot serve as the KeyPath for a component when installing non-advertised shortcuts for the current users."_ – blins Aug 04 '17 at 16:33
-
1the file component itself is the keypath, the shortcut "inherits" the file properties. This way could be a little confusing though when you try track down that desktop shortcut in amongst many files.. user preference as to compact versus traceability i think? – Chris Watts Jan 02 '18 at 13:55
-
In most cases, you wouldn't want to set the shortcut's working directory to the directory that the app is installed into. – Edward Brey May 15 '18 at 18:39
-
This answer shows how to create a valid shortcut per Windows Installer documentation. Wix will build a package (MSI) which will contain a Shortcut record with its `Directory_` field referring to the special `DesktopFolder` folder, and the `Target` field carrying value `[#
]`. The only downside I see is that both the file and the shortcut are part of a single component, so cannot be installed one without the other. Obviously, it makes no sense to install the shortcut without the target file, but now you can't have a "Place shortcut on the desktop" option either. – Armen Michaeli Mar 18 '20 at 16:23 -
Another downside that I missed is that since the keypath is the file the shortcut links to, reparations of installation won't always behave as expected by user -- if the file is there, a missing shortcut won't be repaired (read: installed), since the component is considered present (the file is in place). – Armen Michaeli Apr 30 '20 at 11:22
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>

- 39,960
- 25
- 91
- 164

- 401
- 1
- 4
- 9
It seems lot easier in this documentation.
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.

- 121
- 1
- 4
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>

- 323
- 1
- 6
- 15
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.

- 21
- 3