tags:

views:

1566

answers:

3

Following some example code on the net, I got my first WiX installer to work. However, it placed my program menu shortcut directly on Program Menus. I really want to create a folder, Sample, in Program Menus for my link.

Original Code:

<Shortcut Id="startmenuSample" Directory="ProgramMenuFolder" Name="Sample 0.5"
WorkingDirectory='INSTALLDIR' Icon="Sample.exe" IconIndex="0" Advertise="yes">

Attempt at modifying code (fails with compiler error):

<Shortcut Id="startmenuSample" Directory="ProgramMenuFolder\Sample" Name="Sample 0.5"
WorkingDirectory='INSTALLDIR' Icon="Sample.exe" IconIndex="0" Advertise="yes">

Note the addition of \Sample.

How do I go about adding that link to a new folder in the Program Menu?

+2  A: 

In Windows Installer you need to create a new directory under ProgramMenuFolder and then reference it.

<Directory Id="ProgramMenuFolder" >
  <Directory Id="ProgramMenuDir" Name='My Folder'>
  </Directory>
</Directory>

<Shortcut Id="startmenuSample" Directory="ProgramMenuFolder" Name="Sample 0.5"
  WorkingDirectory='INSTALLDIR' Icon="Sample.exe" IconIndex="0" Advertise="yes">
Shay Erlichmen
My first attempt at trying this failed, though it could certainly be user error. Can you point to a complete example?
Eric J.
+3  A: 

This is a sample test I did, when I was asked to do the same thing

<Package InstallerVersion="200" Compressed="yes" />

<WixVariable Id="Manufacturer" Value="StackOverFlowHelper"/>
<WixVariable Id="ShortProduct" Value="ShortCuts"/>

<Media Id="1" Cabinet="WixShortCut.cab" EmbedCab="yes" />

<Icon Id="ShortCutIcon" SourceFile="YOUR.ico"/>

<!-- The icon that appears in Add & Remove Programs. -->
<Property Id="ARPPRODUCTICON" Value="ShortCutIcon" />

<Directory Id="TARGETDIR" Name="SourceDir">
  <Directory Id="ProgramFilesFolder">

    <Directory Id="ManufacturerFolder" Name="!(wix.Manufacturer)">
      <Directory Id="INSTALLLOCATION" Name="!(wix.ShortProduct)">
        <Component Id="ProductComponent" Guid="{YOUR_GUID}" KeyPath="yes">
          <CreateFolder/>
        </Component>
      </Directory>
    </Directory>
    <Directory Id="ProgramMenuFolder">
      <Directory Id="ProgramMenuManufacturer" Name="!(wix.ShortProduct)" />
    </Directory>
  </Directory>
</Directory>



<DirectoryRef Id="ProgramFilesFolder">
  <Component Id="ProgramMenuShortcuts" Guid="{YOUR_GUID}">
    <CreateFolder Directory="ProgramMenuManufacturer"/>
    <RemoveFolder Id="RemoveMenuShortcuts" Directory="ProgramMenuManufacturer" On="uninstall" />

    <RegistryValue Root="HKCU" Key="Software\!(wix.Manufacturer)\!(wix.ShortProduct)" Name="InstalledStartMenuShortcuts" Type="integer" Value="1" />
  </Component>
</DirectoryRef>

<DirectoryRef Id="INSTALLLOCATION" FileSource="Files">
  <Component Id="WixShortCut" Guid="{YOUR_GUID}">
    <File Id="Test.ShortCut" Vital="yes" Name="A_DOC.pdf" />

    <CreateFolder />
    <RegistryKey Root="HKCU" Key="Software\!(wix.Manufacturer)\!(wix.ShortProduct)" Action="createAndRemoveOnUninstall">
      <RegistryValue Name="ShortCut" Value="1" Type="integer" KeyPath="yes"/>
    </RegistryKey>

    <!-- Shortcut in Start menu. -->
    <Shortcut Id="ProgramMenuApplicationShortcut" Name="!(wix.ShortProduct)" Target="[#Test.ShortCut]"
      Directory="ProgramMenuManufacturer" Show="normal" Icon="ShortCutIcon"/>
  </Component>
</DirectoryRef>

<Feature Id="ProductFeature" Title="WixShortCuts" Level="1">
  <ComponentRef Id="ProductComponent"/>
  <ComponentRef Id="ProgramMenuShortcuts"/>
  <ComponentRef Id="WixShortCut"/>
</Feature>

CheGueVerra
Thank you both for your suggestions. I'm sure both are correct, but this one provided me the key insight I needed. For others learning WiX, you may find this link useful: http://blogs.technet.com/alexshev/pages/from-msi-to-wix.aspx
Eric J.
A: 

Thank you CheCheVerra for the example. I was able to glean a solution to my particular variant on this problem. One question: why is the RemoveFolder element under the CreateFolder element necessary? Without it, Light fails. With it, everything seems to work. Any insight?

barry