How to create a shortcut only if a specific feature is installed?

ImportantThe following article uses options that are available starting with the Enterprise edition and project type.

When creating a complex package sometimes you need to create a shortcut only if a certain feature is installed. This can be done in multiple ways, depending on the behavior you want to obtain.

For this How-To, suppose we have a package with three features: MainFeature, FeatureA and FeatureB. The main feature installs the EXE of the application and the other two features install different shortcuts which call the EXE with different parameters. The names of the EXE is MyApp.exe and the shortcut names are ShortcutA and ShortcutB.

ImportantThe instructions in this How-To refer to the above scenario. For your package you need to adapt the instructions to your files, shortcuts and features.

1. Create a shortcut only if a feature is installed

The shortcuts to an installed file will be added to the component of their target. Since these shortcuts cannot be moved to another component, they cannot be used for multiple features. The solution is to use shortcuts to an external file. This type of shortcuts can be moved to any component, therefore each shortcut can be placed into a different feature.

The package can be configured for our scenario by following these steps:

  1. Go to the Organization page and create the MainFeature, FeatureA and FeatureB features
  2. Make sure that the component of the MyApp.exe file is in MainFeature
  3. Go to the Registry page
  4. Create two registry entries and name them ShortA and ShortB
  5. Go to the "Organization" page
  6. Make sure that the component of the ShortA registry entry is in FeatureA
  7. Make sure that the component of the ShortB registry entry is in FeatureB
  8. Go to the Files and Folders page
  9. Create two shortcuts to an external file and name them ShortcutA and ShortcutB
  10. For each shortcut, set the Shortcut Target field to [APPDIR]MyApp.exe (this is done in the New Shortcut dialog)
  11. Go to the "Organization" page
  12. Make sure the ShortcutA shortcut is in the "ShortA" component
  13. Make sure the ShortcutB shortcut is in the "ShortB" component

When the installation runs, each shortcut will be created only if the feature which contains it is installed.

NoteIn this How-To, we used two registry entries ("ShortA" and "ShortB") to define the components of the two shortcuts. For your package, you can use any components in the features that will contain the shortcuts.

2. Create a shortcut only if a component is installed

If your package needs to create a shortcut only if a specific file or registry entry is installed, you can move the shortcut in the component of this file or registry entry.

In order to create the MyShortcut shortcut only if the MyRegVal registry value is installed, you can follow these steps:

  1. Go to the "Files and Folders" page and make sure that the MyApp.exe file is in your project
  2. Create a shortcut to an external file and name it MyShortcut
  3. In the "New Shortcut" dialog set the Shortcut Target field to [APPDIR]MyApp.exe
  4. Go to the "Registry" page and create the MyRegVal registry value
  5. Go to the "Organization" page and move the shortcut to the component of the MyRegVal registry value

NoteThe component which contains the shortcut can be conditioned. This allows the package to create the shortcut only if a specific criteria is met (for example a checkbox is checked on a custom dialog).

3. Condition the creation of the shortcut

Any component from an installation package can be conditioned. Therefore, by conditioning the component of a shortcut you can make sure that it's installed only if a specific criteria is met.

For using a checkbox to condition the installation of a shortcut to the MyApp.exe file, you can try this approach:

  1. Go to the "Files and Folders" page and create a shortcut to an external file
  2. For this shortcut, set the Shortcut Target field to [APPDIR]MyApp.exe
  3. Go to the "Registry" page and create a registry value (for example MyShortcut)
  4. Go to the "Organization" page
  5. Move the shortcut into the component of the registry value you created
  6. Go to the Dialogs page
  7. Create a custom dialog which contains the checkbox (or modify an existing one)
  8. Make sure the checkbox is selected
  9. In the Properties pane, set the Property Name field to MY_CHECKBOX
  10. Set the Text field to something like Create a shortcut to MyApp.exe
  11. Go to the "Organization" page and select the component of the shortcut
  12. For this component set the Condition field to MY_CHECKBOX

With this configuration the shortcut will be created only if the checkbox is checked.