Search code examples
installationwixwindows-installerwix3

execute commands using wix installer


In my Product.wsx I called one bat file which is executed using power shell. Batch file is uninstalling one .exe(differet app) and coping few folders in C:\temp folder.

In web may placess I read calling BAT file from WIX is not good or advisable. IS there any other way to do the same without calling the bat file

        <SetProperty Id="InvokeTestPS1"
                     Before="InvokeTestPS1"
                     Sequence="execute"
                     Value ="&quot;[POWERSHELLEXE]&quot; -Version 2.0 -NoProfile -NonInteractive -InputFormat None -ExecutionPolicy Bypass -Command &quot;&amp; '[APPLICATIONROOTDIRECTORY]Upgrade\upgradeMentor3_5.bat' ; exit $$($Error.Count)&quot;" />
        <CustomAction Id="InvokeTestPS1"
                      BinaryKey="WixCA"
                      DllEntry="CAQuietExec64"
                      Execute="deferred"
                      Return="check"
              Impersonate="no" />
        <InstallExecuteSequence>
          <Custom Action="InvokeTestPS1" After="InstallFiles">
            <![CDATA[NOT Installed]]>
          </Custom>

Solution

  • For the folders you are copying, if you know beforehand what each folder is named and you don't need to worry about unexpected subfolders, you can use a CopyFile per folder you want to copy. Place them directly under a Component. If there's more variability in what needs to be copied, you can write an immediate custom action that adds temporary rows to the MoveFile table based on the files/folders you discover you need to copy (and the sane to the Directory table as needed).

    For the uninstaller, you could call it instead of either powershell or the .bat file.