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.
Comments 5
This is the option I used with Wix 3.0.2420.0. It also works with non-http protocols.
Posted 19 Mar 2008 at 05:17 ¶It looks like my comment can’t be full displayed, it had some code fragments.
Posted 19 Mar 2008 at 05:28 ¶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)
Posted 19 Mar 2008 at 10:55 ¶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”>
Posted 24 Mar 2008 at 05:42 ¶<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>
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.
Posted 24 Mar 2008 at 07:54 ¶Trackbacks & Pingbacks 6
Link to information about a new WiX custom action to create Internet shortcuts…
Bob Arnson has posted some information on his blog about a new feature he has added to WiX 3.0 that I…
[...] about a new feature he has added to WiX 3.0 that I wanted to link to here. In his post at http://www.joyofsetup.com/2008/03/18/new-wix-feature-internet-shortcuts/, Bob describes the Internet shortcut creation feature that he added to WixUtilExtension. The [...]
[...] we might make some more backward-compatible tweaks to simplify common tasks, like we’ve done a few times [...]
[...] Internet shortcuts, as I described before. [...]
[...] Arguments are the command-line arguments. WixGamingExtension translates SupportTask elements into WixUtilExtension InternetShortcuts; the Name attribute is the name of the shortcut and Address is the [...]
[...] Arguments are the command-line arguments. WixGamingExtension translates SupportTask elements into WixUtilExtension InternetShortcuts; the Name attribute is the name of the shortcut and Address is the [...]