Wix installer: Creation of Desktop and Start Menu shortcuts using Wix

Posted: October 13, 2014 in All, Miscellaneous
Tags: , , , , , ,

Creation of Desktop and Start Menu shortcuts:

In this article I would discuss on creating Start Menu and Desktop shortcuts for an application using Wix installer scripts. I would also discuss about a warning message 1910 which is related to unable to delete desktop shortcut while uninstalling and how to address the issue.
(here I am not going to discuss about creating a Wix installer for the application, rather I assume we
already have a Wix installer and we will be adding Start Menu and Desktop shortcuts to it).

First step, we need to add componentRef’s for start menu and desktop short cuts under Feature element. They are named as ApplicationShortcut, ApplicationShortcutDesktop respectively in the below example.

<Feature Id="ProductFeature" Title="" Level="1">
      ...
      
      
    

Second step, add directories under Fragment for these two folders using ProgramMenuFolder and DesktopFolder keywords as shown below.


        <Directory Id="ApplicationProgramsFolder" Name="" />
      
      
    

Add component for ApplicationShortcut under ApplicationProgramsFolder directory reference.

We need to generate a unique guid for each component. Add shortcut for ApplicationStartMenuShortcut under component. Target property need to refer to Installation folder and should specify the executable name. Assign install folder for WorkingDirectory property so that app related file I/O refers to this location.

The next step is to add RemoveFolder, which will be called during uninstallation process.

Final step is to add a RegistryValue and specify as current user.

Follow the same steps for adding desktop shortcut.

The complete section looks like below:

 <Feature Id="ProductFeature" Title="" Level="1">
      ...
      
      
    
  
  
    
      
        <Directory Id="INSTALLFOLDER" Name="">
          
        
      
      
        <Directory Id="ApplicationProgramsFolder" Name="" />
      
      
    
  
  
    
      <Component Id="ApplicationShortcut" Guid="">
        <Shortcut Id="ApplicationStartMenuShortcut" Name="" Description="" Target="[INSTALLFOLDER]YourApp.exe" WorkingDirectory="INSTALLFOLDER" />
        
        <RegistryValue Root="HKCU" Key="Software\" Name="installed" Type="integer" Value="1" KeyPath="yes" />
      
    
    
      <Component Id="ApplicationShortcutDesktop" Guid="">
        <Shortcut Id="ApplicationDesktopShortcut" Name="" Description="" Target="[INSTALLFOLDER]YourApp.exe" WorkingDirectory="INSTALLFOLDER" />
        
        <RegistryValue Root="HKCU" Key="Software\" Name="installed" Type="integer" Value="1" KeyPath="yes" />
      
    
  

Warning 1910:
One of the issue I have observed with desktop shortcut is, it throws following warning while uninstalling.

Warning 1910. Could not remove Shortcut . Verify that the shortcut file exists and that you can access it.

Uninstallation process can’t delete the desktop shortcut due to above warning. It happens only for desktop shortcut and there are no issues with start menu shortcut. The uninstallation would be successful even though there is warning, however the desktop shortcut wouldn’t be deleted. Based on analysis it looks like it is happening due to file/directory attribute settings of desktop.

To fix this issue, go to C:\Users\Public\Desktop and find desktop.ini file. This is a system file. So if you don’t see it then go to folder options and uncheck following check boxes under view tab to view hidden/system files.

  • Don’t show hidden files, folders, or drives.
  • Hide protected operating system files (Recommended).

Un check above check boxes and desktop.ini file would be visible now.

Go to file properties of desktop.ini and Un-check Read-only to remove read only property.
Now try to uninstall your application and you wouldn’t see the earlier warning message.

Other websites

Comments
  1. Fei says:

    Works great

Leave a comment