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="<App name>" Level="1">
      ...
      <ComponentRef Id="ApplicationShortcut" />
      <ComponentRef Id="ApplicationShortcutDesktop" />
    </Feature>

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

<Directory Id="ProgramMenuFolder">
        <Directory Id="ApplicationProgramsFolder" Name="<App name>" />
      </Directory>
      <Directory Id="DesktopFolder" Name="Desktop"></Directory>
    </Directory>

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="<App name>" Level="1">
      ...
      <ComponentRef Id="ApplicationShortcut" />
      <ComponentRef Id="ApplicationShortcutDesktop" />
    </Feature>
  </Product>
  <Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLFOLDER" Name="<App name>">
          <Directory Id="ENRESOURCESFOLDER" Name="en" />
        </Directory>
      </Directory>
      <Directory Id="ProgramMenuFolder">
        <Directory Id="ApplicationProgramsFolder" Name="<App name>" />
      </Directory>
      <Directory Id="DesktopFolder" Name="Desktop"></Directory>
    </Directory>
  </Fragment>
  <Fragment>
    <DirectoryRef Id="ApplicationProgramsFolder">
      <Component Id="ApplicationShortcut" Guid="<add guid>">
        <Shortcut Id="ApplicationStartMenuShortcut" Name="<app name>" Description="<your app description>" Target="[INSTALLFOLDER]YourApp.exe" WorkingDirectory="INSTALLFOLDER" />
        <RemoveFolder Id="RemoveApplicationProgramsFolder" Directory="ApplicationProgramsFolder" On="uninstall" />
        <RegistryValue Root="HKCU" Key="Software\<Your app folder>" Name="installed" Type="integer" Value="1" KeyPath="yes" />
      </Component>
    </DirectoryRef>
    <DirectoryRef Id="DesktopFolder">
      <Component Id="ApplicationShortcutDesktop" Guid="<Add guid>">
        <Shortcut Id="ApplicationDesktopShortcut" Name="<Your app name>" Description="<Your app description>" Target="[INSTALLFOLDER]YourApp.exe" WorkingDirectory="INSTALLFOLDER" />
        <RemoveFolder Id="RemoveDesktopFolder" Directory="DesktopFolder" On="uninstall" />
        <RegistryValue Root="HKCU" Key="Software\<Your app folder>" Name="installed" Type="integer" Value="1" KeyPath="yes" />
      </Component>
    </DirectoryRef>
  </Fragment>

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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s