Search code examples
wixwix3.11

Wix Toolset v3 - Add custom dialog to WixUI_Minimal with checkbox that conditionally runs an EXE file after installation


I am trying to add a custom dialog with a checkbox that conditionally will run an EXE file after the installation is finished with WiX Toolset v3.11

I have tried the following (and other things) but keep running into syntax errors and can't piece together how to do this properly.

  <Product Id="*" Name="MyCompany Test Installer" Version="1.0.0" Manufacturer="MyCompany" UpgradeCode="{356FCAF3-500B-4EE4-A205-E1AB1915EE55}" Language="1033">
    
    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" Platform="x64" />

    <MediaTemplate EmbedCab="yes" />

    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLFOLDER" Name="MyCompany">
          <Component Id="ProductComponent" Guid="{7BE266C9-156D-4DDC-A5BA-09F7567BBBA3}">
            <File Id="MyExe" Source="ToolPalettesFolderSync.exe" KeyPath="yes" />
          </Component>
        </Directory>
      </Directory>
    </Directory>

    <Feature Id="MainFeature" Title="MyComapny Test Installer" Level="1">
      <ComponentRef Id="ProductComponent" />
      <ComponentRef Id="ToolPalleteFolderSyncShortcut" />
      <ComponentGroupRef Id="INSTALLFOLDER_files" />
    </Feature>

    <Property Id="RUN_EXE" Value="0" />

  <UI>
    <UIRef Id="WixUI_Minimal" />

    <Dialog Id="MyCheckboxDialog" Width="370" Height="270" Title="My Custom Dialog">
        <Control Id="Checkbox" Type="CheckBox" X="20" Y="20" Width="330" Height="17" Property="RUN_EXE" Text="Run MyExecutable after installation?" CheckBoxValue="1" />
        <Control Id="Next" Type="PushButton" X="240" Y="243" Width="56" Height="17" Default="yes" Text="Next">
            <Publish Event="NewDialog" Value="VerifyReadyDlg">1</Publish>
        </Control>
        <Control Id="Back" Type="PushButton" X="180" Y="243" Width="56" Height="17" Text="Back">
            <Publish Event="NewDialog" Value="WelcomeDlg">1</Publish>
        </Control>
    </Dialog>

    <Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="MyCheckboxDialog">1</Publish>
    <Publish Dialog="MyCheckboxDialog" Control="Back" Event="NewDialog" Value="WelcomeDlg">1</Publish>
    <Publish Dialog="MyCheckboxDialog" Control="Next" Event="NewDialog" Value="VerifyReadyDlg">1</Publish>
</UI>

    <InstallExecuteSequence>
      <Custom Action="RunMyExe" After="InstallFinalize">RUN_EXE="1"</Custom>
    </InstallExecuteSequence>

    <CustomAction Id="RunMyExe" FileKey="MyExe" ExeCommand="" Return="asyncNoWait"/>

  </Product>

Visual Studio Error Messages


Solution

  • I suggest taking a look at my open source project called IsWiX. It has templates that make all of this easier. For example you just uncomment one line and presto you get an additional interior dialog wired into the wizard loop. You can look at the source code as an example:

    https://github.com/iswix-llc/iswix/blob/main/Application/IsWiX2022AddIn/VotiveMSISolutionTemplate/SetupProjectTemplate/UI.wxs https://github.com/iswix-llc/iswix/blob/main/Application/IsWiX2022AddIn/VotiveMSISolutionTemplate/SetupProjectTemplate/UI-CustomDialog.wxs

    You're generally going about it correctly but I suspect the order values are wrong for the Publish elements. These vary depending on which built in dialog set you are using. The best thing to do is open it up in ORCA and look at the raw table data to see what the value should be to have the desired effect.

    https://learn.microsoft.com/en-us/windows/win32/msi/controlevent-table

    The exception to note is that each control can publish a most one NewDialog or one SpawnDialog event. If you need to author multiple NewDialog and SpawnDialog control events in this table, also include conditional statements in the Condition fields that ensure at most one event is published. If multiple NewDialog and SpawnDialog control events are selected for the same control, only the event with the largest value in the Ordering column gets published when the control is activated.

    Also, I notice that your EXE is scheduled after InstallFinalize. This is likely incorrect. It should be scheduled BEFORE InstallFinalize. The property should also have a default alue of empty "" not 0 and it should be marked as Secure.

    The way you have it now, it's running outside of the installer transaction so it won't run elevated.