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?

0

2 Answers 2

30

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>
Sign up to request clarification or add additional context in comments.

2 Comments

<Property Id="INSTALLSHORTCUT" Secure="yes"/> Secure must be set to yes in order for this property to be accessed by the condition.
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 <Component>, e.g. <Component ... Directory="APPLICATIONDIR"> (2) The <ShortCut> needs these properties: <Shortcut ... Advertise="no" Target="[#MyApp.exe]" /> (note: it's a file ID in "Target") (3) Add a dummy registry entry to the component like <RegistryValue Root="HKCU" Key="Software\[Manufacturer]\[ProductName]" Type="string" Value="desktop icon = 1" KeyPath="yes" /> to avoid WiX errors. (4) See Felix's comment
-5

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

1 Comment

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)?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.