Automatic account creation is now enabled. Captcha authentication required for account creation and editing unless you are trusted here.

Shortcuts in WiX

From WiX Wiki at MindCapers

Jump to: navigation, search

Contents

Shortcuts with no ICE Problems

How to create an uninstall shortcut (and pass all the ICE validations)

What are Advertised Shortcuts?

Advertised shortcuts are more common that you imagine, and more normal too. Anytime you look at the properties of a shortcut and the Target is greyed out, it'll be an advertised shortcut (differentiating from advertised features). Every Office 2003 shortcut looks like that, so clearly a LOT of people have used them and seen them!

An advertised shortcut goes through the Windows Installer engine rather than running the program (or document) directly. This enables Windows Installer to check that all components of the required feature are present (which it does by examining the KeyPath of each component of the feature that the shortcut links to) and install them or repair them as necessary.

An advertised feature is one that isn't actually installed. This can occur if the entire product is advertised through Group Policy or if the feature is selected to be install-on-first-use. If an advertised feature contains an advertised shortcut, and the user selects that shortcut, the feature will be installed before Windows Installer then launches the shortcut (which should launch the program contained in the feature).

If you've ever seen an Office application prompt you for its install CD when you try to run it from a shortcut, you now know why.

If you don't think you need install-on-demand, repair-on-launch, or the ability for domain administrators to advertise software through Group Policy, by all means use non-advertised shortcuts.

Shortcut Properties

<Shortcut Id='StartMenuShortcut' Directory='ProgramFilesFBBT'
                  Name='Matador 2.1'
                  WorkingDirectory='INSTALLDIR' Icon='Matador.ico' IconIndex='0'
                  Advertise='yes' />
 
> From this code, after an install I get shortcuts created, but the 
> Target field of the shortcut properties has become non-editable, 
> meaning that a user cannot type in command line parameters there. Wix 
> 2 shortcuts had an editable Target field with this code. Am I missing something?

Try changing your Advertise attribute to 'no'. You're creating advertised shortcuts (Advertised="yes") and that's how they work. They let MSI check the health of the feature being invoked so they can't be modified. Use Advertised="no" if you want an editable target (and not the health checking).

Creating Conditional Shortcuts

The basic idea is to place the shortcut in a separate component, and then conditionalize the component. There are a couple of tricks, however.

First, choose a unique property name that will control installation of the shortcut. You probably want to name this property in all capital letters so that it is a public property, and can be set on the command line. I chose INSTALLDESKTOPSHORTCUT. If you want the shortcut to be installed by default, then include the line:

	<Property Id="INSTALLDESKTOPSHORTCUT" Value="1"/>

If you don't want the shortcut to be installed by default, then leave this property out. Note that setting the property to "0" is NOT equivalent to leaving it unset.

Next, add a user interface for setting the property. If you are using the standard WiX UI library, you may need to create a local copy of your chosen dialog in order to modify it. In my case, I modified the InstallDirDlg and added:

	<Control Id="DesktopShortcutCheckBox" Type="CheckBox"
		 X="20" Y="160" Width="290" Height="17"
		 Property="INSTALLDESKTOPSHORTCUT" CheckBoxValue="1"
		 Text="Create a shortcut for this program on the desktop."/>

If you are generating installers in multiple languages, you may want to use a localization variable rather than hard-wiring the text of the control.

Next, if you don't already have a Directory element for the folder where the shortcut will be placed, create one. In my case, I want the shortcut on the desktop so I created the element:

	<Directory Id="DesktopFolder" Name="Desktop"/>

directly under the toplevel Directory element of my installer. See the Windows MSI documentation on System Folder Properties for other system folder property names.

Next, add a new conditional component for your shortcut. This is one of the tricky parts to get right, both because the shortcut needs to point to a file in a different component, and because you need to create an artificial object to act as the KeyPath of the component. In this case, we create an otherwise unnecessary registry key to act as the KeyPath of the component, but an empty file would probably also work. The exact path to the registry key is not important, but it should be unique and be in the conventional HKCU/Software/Company/ Product area of the registry. This component should be an XML sibling to the component that it will be targeting. In my case, it looks like this:

	<Component Id="DesktopShortcut" Guid="...">
	  <Condition>INSTALLDESKTOPSHORTCUT</Condition>
	  <CreateFolder/>
	  <RegistryKey Root="HKCU" Key="Software\Llamagraphics\Life Balance \Install"
	               Action="createAndRemoveOnUninstall">
	    <RegistryValue Name="DTSC" Value="1" Type="integer" KeyPath="yes"/>
	  </RegistryKey>
	  <Shortcut Id="DesktopShortcut" Directory="DesktopFolder"
	            Name="Life Balance" WorkingDirectory="INSTALLDIR"
		    Icon="Application.ico" Target="[#Life_Balance.exe]"/>
	</Component>

Note that "Life_Balance.exe" is the Id of the File element that I want the shortcut to point to. Of course, you should substitute your own company, product, and file ids for the ones I have used here.

Lastly, you need to add the new component to the same feature that installs the target of the shortcut:

	<ComponentRef Id="DesktopShortcut"/>

When you run Light to link the installer, you will get an ICE69 warning that your shortcut targets a file in a different component. You can safely ignore this warning, since both components are in the same feature and will always be installed together.


About Quick Launch Shortcuts

It's ill advised to actually create shortcuts in the Quick Launch folder. This folder does not vary with the ALLUSERS property, so installing shortcuts in here will mean they won't neccesarily get removed on uninstall.

If you have to use QuickLaunch (and have a faciliy to remove them), use AppDataFolder. This will get you into:

C:\Documents and Settings\(UserName)\Application Data\

Then varibilise into the property table:

Microsoft\Internet Explorer\Quick Launch

Other Resources


Shortcut to Exe in Another Component

Question - Is it possible to create a shortcut in one component, that will

reference to an executable which is located in another component? We have an executable used by all our applications, but is running with different command line arguments for each component. So I want the executable to be placed in a single components and to create the shortcuts from all the other components. How can I achieve that?

Answer - You can set the shortcut target to be any file that is installed using

its ID with a '#' prefix, e.g.

<Component Id="MyShortcut" Guid="..." > <Shortcut Id="MyApp.Shortcut" Name="My Application" Target="[#myapp.exe]" Directory="DesktopFolder" Show="normal" /> </Component>

However, you might get warnings if the two components are not part of the same feature.

Personal tools