WIX invoking Batch file in InstallExecution Sequence

Girish picture Girish · Mar 5, 2012 · Viewed 17.5k times · Source

I am new to WIX and I am trying to invoke a batch file from my WIX installer. MyBatch.bat contains a simple Copy of a Text file from c:\ to D:\

I am unable to invoke the batch file. Below is my code.

Please help me out.

  <?xml version="1.0" encoding="UTF-8"?>
  <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <?define ProductName='Test Product' ?>
  <?define ProductVersion='1.0.0.0' ?>
  <?define ProductCode='b7bc7c6f-9a4e-4973-be84-eca8e3427c97'?>
  <?define UpgradeCode='06a81104-1e30-463d-87e1-e8a79b4c682a'?>
  <?define Manufacturer='Respond'?>
  <Product Id="$(var.ProductCode)" Language="1033" Version='$(var.ProductVersion)' Name='Respond'
  Manufacturer='$(var.Manufacturer)' UpgradeCode='$(var.UpgradeCode)'>
    <Package InstallerVersion='200' Compressed='yes' />
    <Media Cabinet='media1.cab' EmbedCab='yes' Id ='1' />
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id='ProgramFilesFolder'>
        <Directory Id='INSTALLDIR' Name='$(var.ProductName)'>
          <Component Id='ProductComponent' Guid='b11556a2-e066-4393-af5c-9c9210187eb2'>
            <File Id='Calc' DiskId='1' Source='C:\WINDOWS\system32\calc.exe'/>
            <File Id='my_batch_script' Name='MyBatch.bat' DiskId='1' Source='MyBatch.bat'   />
          </Component>
        </Directory>
      </Directory>
      <Directory Id='ProgramMenuFolder'>
        <Directory Id='ApplicationProgramsFolder' Name='$(var.ProductName)'>
          <Component Id='MainExecutable' Guid='EDED00D8-2465-46CA-86D6-B20DE921EFA6'>
            <Shortcut Id='ShortcutCalc' Description='$(var.ProductName)' Name ='Calculator of Windows'
            Target='[INSTALLLOCATION]Calc.exe' WorkingDirectory='INSTALLLOCATION'/>
            <RemoveFolder Id='ApplicationProgramsFolder' On='uninstall'/>
            <RegistryValue Root='HKCU' Key='Software\$(var.Manufacturer)\$(var.ProductName)' Type ='multiString'
            Name='installed' Value='1' KeyPath='yes'/>
          </Component>
        </Directory>
      </Directory>
    </Directory>

    <Feature Title='SetupProject1' Level='1' Id ='AppFeature'>
      <ComponentRef Id='ProductComponent' Primary='yes'/>
      <ComponentRef Id='MainExecutable'/>
    </Feature>

    <Property Id='WIXUI_INSTALLDIR' Value='INSTALLDIR' ></Property>
    <WixVariable Id='WixUILicenseRtf' Overridable='yes' Value='License.rtf'/>
    <?include CustomActions.wxi?>
    <UI>
      <?include UISequence.wxi?>
      <?include Dialogs.wxi?>
    </UI>

    <CustomAction Id="BatchCmd" Property="ThePath" Value="[INSTALLDIR]MyBatch.bat" />
    <CustomAction Id="BatchRun" Property="ThePath" ExeCommand='"[INSTALLDIR]MyBatch.bat"' Return='asyncWait' Impersonate="yes"/>

    <InstallExecuteSequence>
      <Custom Action="BatchCmd" After="InstallFiles" >Not Installed </Custom>
      <Custom Action="BatchRun" After="BatchCmd">Not Installed </Custom>
    </InstallExecuteSequence>
  </Product>

</Wix>

Answer

Girish picture Girish · Mar 6, 2012

This worked for me.

<CustomAction Id="test"
    ExeCommand="[INSTALLDIR]MyBatch.bat"
    Directory="INSTALLDIR" Execute="deferred" Return="asyncWait"/>

<InstallExecuteSequence>
    <Custom Action="test" After="InstallFiles">NOT Installed</Custom>
</InstallExecuteSequence>