WIX calls a batch file in the InstallExecution sequence

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 can not call the batch file. Below is my code.

Please help me.

<?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> 
+4
source share
4 answers

It 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> 
+4
source

It seems you are solving your problem with the wrong tool. If the file to copy is part of your application, you should write Component with this File inside. Otherwise, if you just need to copy some external file that is already present on the target system, you must authorize the CopyFile element, its nested element in the component.

+2
source

I agree with Yang , you are not solving your task correctly.


As for batch files, they are not executed independently, like .exe, it is cmd.exe , which reads the bat file and executes it line by line.

To run a batch file, you must run it as follows:

 cmd.exe /c batch.bat 
+1
source

Add your CustomAction rejection as follows. Make sure Return = "ignore" if you are not returning anything from the bat file.

 <CustomAction Id="RunBat" Directory="your_directory" ExeCommand='"c:\test\test.BAT"' Execute='deferred' Impersonate='no' Return='ignore'/> 

Also in the installExecuteSequence sequence add an action before InstallFinalize

 <InstallExecuteSequence> <Custom Action="RunBat" Before="InstallFinalize">NOT (REMOVE~="ALL")</Custom> </InstallExecuteSequence> 
0
source

Source: https://habr.com/ru/post/1399737/


All Articles