4

I'm writing an installer for a per-machine application. There is a checkbox for the user to request a desktop shortcut.

My first attempt used a component with a conditional statement to create the shortcut - this looked like:-

    <Component
       Id="C_desktopShortcut"
       Guid="PUT_GUID_HERE">

       <Condition>INSTALLDESKTOPSHORTCUT</Condition>

       <Shortcut
          Id="S_DT_ReadMe"
          Name="ReadMe.txt"
          Description="ReadMe shortcut"
          Target="[INSTALLFOLDER]ReadMe.txt" />

       <RegistryValue
          Root="HKCU"
          Key="Software\MyTest\Shortcut"
          Name="DesktopShortcutInstalled"
          Type="integer"
          Value="1"
          KeyPath="yes" />
    </Component>

This does work, but because it's a per-machine install will result in orphaned registry keys if installed by one admin user and removed by another. (As described in (WiX) Program files shortcut for per-machine install.)

I then reworked the code to create a shortcut in the same component that loads the main executable, for example:-

    <ComponentGroup
       Id="CG_ProductComponents"
       Directory="INSTALLFOLDER">
          <Component
             Id="C_ReadMeFile"
             Guid="PUT_GUID_HERE">
             <File
                Id="FILE_ReadMeTxt"
                Source="..\Docs\ReadMe.txt"
                KeyPath="yes">

            <Shortcut 
                Advertise="yes"
                Id="SH2_readme"
                Directory="DesktopFolder"
                Name="TestReadMe"
                WorkingDirectory="INSTALLDIR"
                Description="Test shortcut">
         </Shortcut>
     </File>
  </Component>

However, with this approach I can't find a way to add a condition to control whether the shortcut is installed.

Despite extensive searching, I've been unable to find a technique that allows for a conditional desktop shortcut, yet avoids the pitfall of orphaned registry keys.
Please can someone tell me how I should tackle this problem with WiX.

Thanks

Community
  • 1
  • 1

1 Answers1

0

Have you tried installing registry to HKLM instead of HKCU.

Ashish Kamat
  • 567
  • 4
  • 16
  • Already tried that, thanks. The compiler throws errors ICE57 "both per-user and per-machine data with a per-machine KeyPath" ICE38 "Component installs to user profile. It's KeyPath registry key must fall under HKCU." – Dave Vaughan Dec 10 '15 at 07:09