How do I create a shortcut only if a specific feature is installed?AnswerWhen 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 lets 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 shortcuts 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.
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 that the ShortcutA shortcut is in the
"ShortA" component
- make sure that 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.
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).
Condition the creation of the shortcutAny component
from an installation package can be conditioned. Therefore, by
conditioning the component of a shortcut you can make sure that the 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 that 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. |