How to create a shortcut only if a specific feature is installed?
The 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.
The 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:
- Go to the Organization page and create the MainFeature, FeatureA and FeatureB features
- Make sure that the component of the MyApp.exe file is in MainFeature
- Go to the Registry page
- Create two registry entries and name them ShortA and ShortB
- Go to the "Organization" page
- Make sure that the component of the ShortA registry entry is in FeatureA
- Make sure that the component of the ShortB registry entry is in FeatureB
- Go to the Files and Folders page
- Create two shortcuts to an external file and name them ShortcutA and ShortcutB
- For each shortcut, set the Shortcut Target field to [APPDIR]MyApp.exe (this is done in the New Shortcut dialog)
- Go to the "Organization" page
- Make sure the ShortcutA shortcut is in the "ShortA" component
- 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.
In 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:
- Go to the "Files and Folders" page and make sure that the MyApp.exe file is in your project
- Create a shortcut to an external file and name it MyShortcut
- In the "New Shortcut" dialog set the Shortcut Target field to [APPDIR]MyApp.exe
- Go to the "Registry" page and create the MyRegVal registry value
- Go to the "Organization" page and move the shortcut to the component of the MyRegVal registry value
The 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:
- Go to the "Files and Folders" page and create a shortcut to an external file
- For this shortcut, set the Shortcut Target field to [APPDIR]MyApp.exe
- Go to the "Registry" page and create a registry value (for example MyShortcut)
- Go to the "Organization" page
- Move the shortcut into the component of the registry value you created
- Go to the Dialogs page
- Create a custom dialog which contains the checkbox (or modify an existing one)
- Make sure the checkbox is selected
- In the Properties pane, set the Property Name field to MY_CHECKBOX
- Set the Text field to something like Create a shortcut to MyApp.exe
- Go to the "Organization" page and select the component of the shortcut
- For this component set the Condition field to MY_CHECKBOX
With this configuration the shortcut will be created only if the checkbox is checked.