17

I'm using the WiX Tool to create an installer.

I need the installer to make it optional, when creating Start Menu and Desktop shortcuts.

Something like: [   ] Do you want to create a start menu shortcut?

Is that possible?

woderkant
  • 31
  • 5
JakobJ
  • 1,253
  • 3
  • 16
  • 29

2 Answers2

27

Yes, this is definitely possible. The general idea is to make the shortcut component be conditional on a property, then customize your UI to connect a checkbox to that property.

All of this is described (though not for your specific example) in the Wix Tutorial, an insightful read. But here are some more specific code samples for your case:

Add a Property

Create a property that you can hook the checkbox up to. In your .wxs file, add a Property to store the value in.

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product ...>
    <Property Id="INSTALLSHORTCUT" />
  </Product>
</Wix>

Add a Condition

Add a Condition to the component that installs the shortcut, so it's conditional on the value of your new INSTALLSHORTCUT property.

<Component Id="ProgramFilesShortcut" Guid="*">
  <Condition>INSTALLSHORTCUT</Condition>
  <Shortcut Id="ProductShortcut" ... />
</Component>

Add the Checkbox

You need to customize a dialog to add a checkbox to the UI and hook it up to the INSTALLSHORTCUT property. I won't go into all the details here, but there's a good tutorial here: User Interface Revisited

You'll need to download the wix source tree to get the .wxs files for the UI you are using. To add the checkbox to the InstallDir dialog in the WixUI_InstallDir UI, for example, you would download WixUI_InstallDir.wxs and InstallDirDlg.wxs. Add them to your Wix project and rename them (e.g., Custom_InstallDir.wxs and Custom_InstallDirDlg.wxs).

Edit Custom_InstallDirDlg.wxs to add your checkbox. Give the <Dialog> a new Id too:

<Wix ...>
  <Fragment>
    <UI>
      <Dialog Id="InstallDirAndOptionalShortcutDlg" ...>
        <Control Id="InstallShortcutCheckbox" Type="CheckBox" 
                 X="20" Y="140" Width="200" Height="17" 
                 Property="INSTALLSHORTCUT" CheckBoxValue="1" 
                 Text="Do you want to create a start menu shortcut?" />
       </Dialog>
     </UI>
   </Fragment>
 </Wix>

Edit Custom_InstallDir.wxs to use the customized InstallDirAndOptionalShortcut dialog:

<Wix ...>
  <Fragment>
    <UI Id="Custom_InstallDir">

      ** Search & Replace all "InstallDirDlg" with "InstallDirAndOptionalShortcut" **

    </UI>
  </Fragment>
</Wix>

Finally, reference your customized UI in your main .wxs file:

<Wix ...>
  ...
  <UIRef Id="Custom_InstallDir" />
  ...
</Wix>
Vojtech Vrbka
  • 5,342
  • 6
  • 44
  • 63
Nate Hekman
  • 6,507
  • 27
  • 30
  • 2
    `` Secure must be set to yes in order for this property to be accessed by the condition. – Felix Castor Feb 11 '20 at 14:21
  • 1
    Good answer, but a little bit incomplete. To get it run I **additionally** had to **do this in the component** snippet: **(1)** Add a `Directory` property to ``, e.g. `` **(2)** The `` needs these properties: `` (note: it's a file ID in "Target") **(3)** Add a dummy registry entry to the component like `` to avoid WiX errors. **(4)** See Felix's comment – Beauty Apr 22 '21 at 09:00
-5

On the checkbox click event or on the next button click you can call an custom action to create shortcuts.

Sunil Agarwal
  • 4,097
  • 5
  • 44
  • 80
  • I'm trying to use a checkbox for the user to chose to install a file (or not). I followed these steps and it did not work. Is there something missing in the capture of the check box interaction (like a publish command or something)? – tatmanblue Jan 13 '17 at 20:33