New WiX feature: Internet shortcuts

A common request on wix-users is how to create shortcuts to a Web site. MSI’s Shortcut table and CreateShortcuts action don’t support targets that point to URLs like http://www.joyofsetup.com/. A shortcut’s target can point only to a feature (for advertised shortcuts) or a file or directory (for unadvertised shortcuts).

You can fake a shortcut to a URL by using the IniFile table to create a .url file. It’s a bit of a hack, given that the format of .url files isn’t explicitly documented and is therefore subject to change. (Granted, it’s not likely to change, because that would break a lot of existing applications.)

I needed URL shortcuts for Train Simulator so I wrote a custom action to create them. I then added authoring support to the WixUtilExtension compiler extension. With reviews from Heath and Peter, I checked in the work today. You’ll see it in the next weekly build of WiX v3.

The authoring is similar to, but simpler than, a standard shortcut. Here’s the attribute schema reference from WiX.chm:

Name Type Description Required
Id String Unique identifier in your installation package for this Internet shortcut. Yes
Directory String Identifier of the directory where the shortcut should be created. Yes
Name String The name of the shortcut file, which is visible to the user. (The .lnk extension is added automatically and by default, is not shown to the user.) Yes
Target String URL that should be opened when the user selects the shortcut. Windows opens the URL in the appropriate handler for the protocol specified in the URL. Note that this is a formatted field, so you can use [#fileId] syntax to refer to a file being installed (using the file: protocol). Yes

Here’s what a simple http shortcut looks like:

<util:InternetShortcut
Id=”Home”
Directory=”DesktopFolder”
Name=”Joy of Setup”
Target=”http://joyofsetup.com” />

You can also create shortcuts to resources using non-http protocols:

<util:InternetShortcut
Id=”ARP”
Directory=”ProgramMenuFolder”
Name=”ARP”
Target=”file://[%WINDIR]\Help\addremov.chm” />

Internet shortcuts are needed, among other reasons, for Vista’s Game Explorer. More on that in a future entry.

11 thoughts on “New WiX feature: Internet shortcuts”

  1. This is the option I used with Wix 3.0.2420.0. It also works with non-http protocols.

  2. It looks like my comment can’t be full displayed, it had some code fragments.

  3. Yeah, WordPress doesn’t much like XML’s angle brackets…I write posts using Windows Live Writer, which automatically escapes code for me. Try posting without the angle brackets. It won’t compile but will get the point across.8)

  4. One more time… This is the option I used with Wix 3.0.2420.0

    <CustomAction Id=”Set_HomeUrl” Property=”HomeUrl” Value=”www.google.com”/>

    <InstallExecuteSequence>
    <Custom Action=”Set_HomeUrl” After=”InstallFiles”/>
    </InstallExecuteSequence>

    <InstallUISequence>
    <Custom Action=”Set_HomeUrl” After=”ExecuteAction”/>
    </InstallUISequence>

    <Directory Id=”TARGETDIR” Name=”SourceDir”>
    <Directory Id=”ProgramMenuFolder”>
    <Directory Id=”MyDirectory” Name=”MyDirectory”>
    <Component Id=”MyComponent” Guid=”PUT-YOUR-GUID-HERE”>
    <RegistryValue Root=”HKCU”
    Key=”MyProduct”
    Type=”string”
    Value=”StartMenuFolder”
    KeyPath=”yes” />
    <RemoveFolder Id=”MyDirectory” On=”uninstall”/>
    <Shortcut Id=”Google_Shortcut” Target=”[HomeUrl]” Icon=”Google.ico” Directory=”MyDirectory” Name=”Google Home” Description=”Google”>
    <Icon Id=”Google.ico” SourceFile=”Google.ico”/>
    </Shortcut>
    </Component>
    </Directory>
    </Directory>
    </Directory>

  5. Yeah, that works too. In fact, you don’t even need the custom action to set the property. I couldn’t get confirmation that it’s supported, however, so it fell into the same “bucket” as the IniFile/.url trick.

Comments are closed.