Adding a Programs Menu Shortcut to Windows Installer 1.2 Packages Created with Visual Studio Installer V. 1.1

This procedure requires you to manually edit the msi file created by VSI1.1 manually using the Orca tool.  Download the Microsoft Windows Installer SDK if you do not already have Orca installed.

The SDK can be found at:

http://www.microsoft.com/msdownload/platformsdk/sdkupdate/

After downloading the SDK start the Orca application and follow the steps outlined.

Phase 1:  Creating the Directory Definitions

First you need to make sure the Program Menu folder is defined in the msi Directory table.

1)  Open the mis in Orca. Select the Directory table. Look to see if there is already a ProgramMenuFolder element. (If you are using VS 1.1 to create the setup this entry will not exist.)

2)  If it does not already exist, then create the ProgramMenuFolder definition by selecting Tables, Add Row. Enter the following field values:

 

Field Name Value
Directory ProgramMenuFolder
Directory_Parent TARGETDIR
DefaultDir .

 

(The DefaultDir value is a single period)

 

3)  Create a unique ID based on a GUID (generate one with the GUIDGEN tool that ships with VS).  Remove the braces and all hyphenations and then add an underscore prefix to the string.  The result should look something like this:

_51AB71ACD3B646EAA292EB4A3766037E

4)  Next create an entry for the Directory table entry for the shortcut by selecting Tables, Add Row from the main menu.  In this case your Directory field will use the GUID value created in Step 3).  The DefaultDir value is the string that you wish to appear in Start, Programs

When you are done the row should look something like this (with your values substituted for Directory and DefaultDir):

 

Field Name Value
Directory _51AB71ACD3B646EAA292EB4A3766037E
Directory_Parent ProgramMenuFolder
DefaultDir My Application

 

Phase 2:  Creating the Shortcut Definition

Next you need to add an entry to the Shortcut table.

1)  Create a second unique GUID and format it exactly as described in Phase 1 Step 3.  The result should look something like this:

_D9602ED3462D42089F236B5AC7A17494

2)  Determine the id assigned to the application to be started by the menu shortcut.  This is found in the Component table under the Component column (NOT the ComponentId column!!!).  Record this id for later use.  In this example the ID for the main executable is:

_67EFC7B528F24EC0938FB8DC92BF8B32

3)  Next create an entry  in the Shortcut table selecting Tables, Add Row from the main menu.   Important values are described below:

        The Shortcut value is the unique GUID created in Phase 2 Step 1).

        The Directory value is the unique GUID string that identifies the directory created in Phase 1 Step 3).

        The Name value is the string you wish to appear in the child menu that is expanded after the main entry in the Start, Programs menu is selected.

       The Component value is the id obtained from Phase 2 Step 2) and identifies the target executable file for the menu shortcut.

        The Target value is defined as _MainFeature, because by default the VSI 1.1 Installer wizard lumps all components into a single feature named _MainFeature.

        The ShowCmd value should be set to 1.

The remaining values can be left blank usually.  If your application needs command line arguments when it starts these are added to the Arguments fields.  Also, the the working directory is typically set to the application folder.  Using the various GUID strings from this example, the final Shortcut table entries should be:

 

Field Name Value
Shortcut _D9602ED3462D42089F236B5AC7A17494
Directory _51AB71ACD3B646EAA292EB4A3766037E
Name Launch My Application
Component _67EFC7B528F24EC0938FB8DC92BF8B32
Target _MainFeature
Arguments  
Description  
Hotkey  
Icon  
IconIndex  
ShowCmd 1
WkDir TARGETDIR

 

4)  Save the msi file, close it, then run the setup to test that everything works.

Phase 3:- Adding an Icon to the shortcut  (optional)

Adding an icon to a shortcut is simple.  Icons are easily added to the msi package - you simply create a unique name for each icon, and browse to the graphic file to import the icon into the package. 

There is one peculiarity that should be mentioned.  According to the SDK documentation, the icon MUST be named in the setup table with the same extension as the target file the shortcut points to.  So, for example, if you were to create a shortcut to an HTML help file, with an icon file named "HelpIcon.ico", then presumably the icon would need to be defined in the msi table as "HelpIcon.chm" - i.e. with a .chm extension to match the target extension of the HTML help file.

I have found from trial and error that this statement is not true.  What IS true is that Windows Installer V1.2 does not like icon entries with NO extension.  So in practical terms you could name the icon "HelpIcon.ico", "HelpIcon.chm" or even "HelpIcon.exe" and all will work fine.  But if you name the icon "HelpIcon" the image will not appear with the shortcut.

To make a long story short, the logical thing to do is simply preserve the original icon name complete with the .ico extension, and it will work for all cases.

Step 1)  Add the icon to the msi database by selecting the Icon table in Orca and then Tables, Add Row from the main menu.  If your icon is named "MyAppIcon.ico" use that for the Name table value.  Clicking on the Data element will display a browser dialog.  Browse to the physical icon file and select it.  The icon will be embedded in the msi package as a binary stream at this point.

Step 2)  Modify the Shortcut table entry to the following:

 

Field Name Value
Shortcut _D9602ED3462D42089F236B5AC7A17494
Directory _51AB71ACD3B646EAA292EB4A3766037E
Name Launch My Application
Component _67EFC7B528F24EC0938FB8DC92BF8B32
Target _MainFeature
Arguments  
Description  
Hotkey  
Icon MyAppIcon.ico
IconIndex 0
ShowCmd 1
WkDir TARGETDIR

 

The IconIndex value is set to 0 because the icon file contains only one image.   According to the documentation you can add a single file that contains multiple icons and then reference the one you want by index.  However I have not actually tried this, and nothing in the documentation can be taken at face value as accurate :-).   If you stick with single icon files and use an IconIndex value of 0 it will definitely work.

Step 3)  Save the msi file, close it and run the setup to test.