Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Create Shortcut" Checkbox

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?

like image 366
JakobJ Avatar asked Jan 11 '11 13:01

JakobJ


1 Answers

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>
like image 171
Nate Hekman Avatar answered Sep 20 '22 19:09

Nate Hekman