Search code examples
c#wixwindows-installer

How to passing checkbox values to MSI file WIX


I've created WPF of setup file and got a checkbox to user decide show "desktop shortcut". But i got a problem to sending it to MSI File.

This is creating desktop shortcut. But I wanna add a condition in here. If WPF checkbox is checked "i wanna add it to desktop" if not nothing happens.

<Component Id="DesktopShortcutComponent" Guid="*">
        <RegistryValue Id="RegShortcutDesktop" Root="HKCU" Key="SOFTWARE\MyProject\1.0\settings" Name="DesktopSC" Value="1" Type="integer" KeyPath="yes" />
        <Shortcut Id="desktopSc" Target="[MYINSTALLFOLDER]\MyApplication.exe" Directory="DesktopFolder" Name="MyApplication" Icon="MyProductIcon" IconIndex="0" WorkingDirectory="MYINSTALLFOLDER" Advertise="no" />
        <RemoveFolder Id="RemoveShortcutFolder" On="uninstall" />
    </Component>

How to passing values between custom created wpf to msi file?

Do i have to use "string values of bootstrapper"?

BootstrapperApplication.Engine.Plan["checkBoxValues"] 

Solution

  • You can setup string or numeric variable like this

    BootstrapperApplication.Engine.StringVariables["InstallDir"] = "somePath";
    BootstrapperApplication.Engine.StringVariables["Cbx"] = "True";
    BootstrapperApplication.Engine.NumericVariables["Variable"] = 1;
    

    in Bundle.wxs

    <Variable Name="InstallDir"
                  bal:Overridable="yes" />
    <Variable Name="Cbx"
                  bal:Overridable="yes"/>
    
    
    <MsiPackage SourceFile="$(var.Some.Setup.TargetDir)Some.Setup.msi"
                      Id="InstallationPackageId"
                      Visible="no">
        <MsiProperty Name="INSTALLFOLDER" Value="[InstallDir]" />
        <MsiProperty Name="CBX" Value="[Cbx]" />
    </MsiPackage>
    

    Product.wxs

    <Property Id="CBX" Value="False" Secure="yes" />
    
    <Component Id="Shortcut"
               Directory="INSTALLFOLDER"
               Guid="68D52920-E643-42F9-B1C6-8D9D1D8C8B2E">
       <RegistryValue Id="RegShortcutDesktop"
                      Root="HKCU"
                      Key="SOFTWARE\MyProject\1.0\settings"
                      Name="DesktopSC"
                      Value="1"
                      Type="integer"
                      KeyPath="yes" />
       <Shortcut Id="desktopSc"
                 Target="[INSTALLFOLDER]\Podit.exe"
                 Directory="INSTALLFOLDER"
                 Name="Podit"
                 Icon="icon.ico"
                 IconIndex="0"
                 WorkingDirectory="INSTALLFOLDER"
                 Advertise="no" />
       <Condition><![CDATA[CBX = "True"]]></Condition>
    </Component>