How to create a multi-level subfolder in Start menu using WiX

Levon picture Levon · Jan 22, 2009 · Viewed 13.6k times · Source

How do I create sub folders (several levels deep) in the Windows Start menu, using WiX?

Currently I am able to put my shortcut in the Start menu, but only in a folder immediately under Programs (Start / Programs / MyFolder), but I want to nest my shortcut deeper (Start / Programs / MyPlatform / MyProduct / etc.). I tried different combinations, but alas.

<DirectoryRef Id="StartMenuMyProduct">
    <Component Id="ApplicationShortcut" Guid="{PUT-SOME-GUID-HERE}">
        <Shortcut Id="ApplicationStartMenuShortcut"
                  Name="Configure My Product"
                  Description="Add or remove this and that"
                  Target="[MYPRODUCTDIR]ConfigureMyProduct.exe"
                  WorkingDirectory="MYPRODUCTDIR"/>
        <RemoveFolder Id="StartMenuMyProduct"
                      On="uninstall"/>
        <RemoveFolder Id="StartMenuMyPlatform"
                      On="uninstall"/>
        <RegistryValue Root="HKCU"
                       Key="SOFTWARE\MyCompany\MyPlatform\My Product"
                       Name="Installed"
                       Type="integer"
                       Value="1"
                       KeyPath="yes"/>
    </Component>
</DirectoryRef>

<!-- Shortcut to the configuration utility in the Windows Start menu -->
<Directory Id="ProgramMenuFolder">
    <!--<Directory Id="StartMenuMyPlatform" Name="MyPlatform">-->
      <Directory Id="StartMenuMyProduct" Name="My Product" />
    <!--</Directory>-->
</Directory>

Answer

Wim Coenen picture Wim Coenen · Jan 23, 2009

What makes things interesting is that MSI demands a registry value to be created as a way to detect whether the component has been installed. If we prefer to create only one such registry value for all shortcuts, then we'll have to put all our shortcuts in a single component.

Fortunately it is possible to create components which span multiple target directories by making use of the Directory attribute on the Shortcut element.

   <!-- shortcuts to applications in the start menu -->
   <DirectoryRef Id="ProgramMenuProductFolder">
      <Component Id="ProgramMenuShortcutsComponent" Guid="PUT-GUID-HERE">
         <!-- create folders -->
         <CreateFolder Directory="ProgramMenuVendorFolder" />
         <CreateFolder Directory="ProgramMenuProductFolder" />
         <CreateFolder Directory="ProgramMenuSubFolder" />
         <!-- remove folder -->
         <RemoveFolder Id="RemoveProgramMenuVendorFolder"
            Directory="ProgramMenuVendorFolder"
            On="uninstall" />
         <RemoveFolder Id="RemoveProgramMenuProductFolder"
            Directory="ProgramMenuProductFolder"
            On="uninstall" />
         <RemoveFolder Id="RemoveProgramMenuProductSubFolder"
            Directory="ProgramMenuProductSubFolder"
            On="uninstall" />
         <!-- main shortcut -->
         <Shortcut
            Id="MainShortcut"
            Name="My Product"
            Target="[SomeInstalledFolder]app1.exe" />
         <!-- shortcut in subfolder -->
         <Shortcut
            Id="SubFolderShortcut"             
            Name="mySubFolderShortcut"
            Target="[SomeInstalledFolder]app2.exe"
            Directory="ProgramMenuProductSubFolder" />
         <!--
            RegistryValue whichs serves as KeyPath
         -->
         <RegistryValue
            Root="HKCU"
            Key="Software\MyVendor\MyProduct"
            Name="InstalledStartMenuShortcuts"
            Type="integer"
            Value="1" />
      </Component>
   </DirectoryRef>

   <!-- shortcut directories -->
   <Directory Id="ProgramMenuFolder">
      <Directory Id="ProgramMenuVendorFolder" Name="MyVendor">
         <Directory Id="ProgramMenuProductFolder" Name="MyProduct">
            <Directory Id="ProgramMenuProductSubFolder" Name="MySubFolder" />
         </Directory>
      </Directory>
   </Directory>