0

Currently I have failed to pass parameters from CAQuiteExec to cmd.exe batch. (Inspired by wix, install files and run bat file)

In deferred sequence, the installer can call commandline command "copy" and "echo" but parameter %1 is always blank...

I want to pass a Value="HAHIHUHEHO" of Property "BATCHPARAMETER" to the configure.bat. But ECHO returns its own status "ON" (same as only ECHO without any input parameter....)

Any ideas?

<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Id="MY-UID" Name="my_name" Language="1033" Version="1.11.5164" Manufacturer="company" UpgradeCode="MY-UID">
        <Package Description="Test file in a Product" Comments="Simple test" InstallerVersion="200" Compressed="yes" />
        <Media Id="1" Cabinet="simple.cab" EmbedCab="yes" />
        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="ProgramFilesFolder" Name="PFiles">
                <Directory Name="my_folder" Id="MY_FOLDER">
                  <Component Id="CONFIGURE.BAT" DiskId="1" Guid="MY-UID">
                         <File KeyPath="yes" Id="file_configure.bat" Name="configure.bat" Source="configure.bat" />
                  </Component>  
                </Directory>
            </Directory>
        </Directory>
        <Feature Id="MainFeature" Title="Main Feature" Level="1">
                   <ComponentRef Id="CONFIGURE.BAT" />
        </Feature>
        <UI />
        <UIRef Id="WixUI_Minimal" />

        <Property Id="BATCHPARAMETER" Value="HAHIHUHEHO" Secure="yes" />
        <CustomAction Id="SetCustomActionData" Return="check" Property="BatchCmd" Value="[BATCHPARAMETER]" />

        <CustomAction Id="BatchCmd" Property="BatchRun" Value="&quot;[#file_configure.bat]&quot;" Execute="immediate">
        </CustomAction>

        <CustomAction Id="BatchRun" BinaryKey="WixCA" DllEntry="CAQuietExec" Execute="deferred" Return="check" Impersonate="yes">
        </CustomAction>
        <InstallExecuteSequence>
            <Custom Action="SetCustomActionData" Before="BatchCmd"></Custom>

            <Custom Action="BatchCmd" Before="BatchRun">NOT Installed</Custom>

            <Custom Action="BatchRun" After="InstallFiles">NOT Installed</Custom>
        </InstallExecuteSequence>  
    </Product>
</Wix>

configure.bat content is below: It copies the hoge.txt to a hoge{%date% without slash}.txt and writes %1 parameter inside.

setlocal
echo on

copy /Y C:\temp\hoge\hoge.txt C:\temp\hoge\hoge%date:~-10,4%%date:~-5,2%%date:~-2,2%.txt
echo %1 > C:\temp\hoge\hoge%date:~-10,4%%date:~-5,2%%date:~-2,2%.txt 2>&1
echo off
endlocal
exit /B 0
illuminate33
  • 117
  • 1
  • 9

3 Answers3

0

You're using the incorrect 'Value' for the custom action data. (I think you also meant to use Property="BatchRun" as this is the deferred custom action??)

<CustomAction 
  Id="SetCustomActionData" 
  Return="check" 
  Property="BatchRun" 
  Value="BATCHPARAMETER=[BATCHPARAMETER]" />

Take a look at this answer for a more in-depth example of custom action data. You can also do multiple property values in one custom action by separating properties with a ;.

If you are going to use a deferred custom action, don't just run a bat file inside your custom action, rewrite the behaviour of the bat file in the custom action itself so there's no need for a bat file in the first place.

Brian Sutherland
  • 4,698
  • 14
  • 16
  • Thank you very much for your kind answer. I'm afraid I cannot verify your teaching in my code for unrelated incidental tasks immediately. If you please, would you teach me more about "rewrite the behaviour of the bat file in the custom action itself "...? – illuminate33 Feb 01 '18 at 04:46
  • I confirmed that the way of passing a value to a key in the Value ="key = [parameter]" Thank you ! But I failed to pass a value to the batch file in QuietExec...It seems that QuietExec prohibits embedded parameter in ExeCommand....or simply I don't know how to do in QuietExec. (At least for now, I don't need QuietExec ) Please see my answer. – illuminate33 Feb 03 '18 at 15:26
0

This is self reply and not exact answer,

but I finally get output "HAHIHUHEHO" in C:\temp\hoge\hoge{%date%}.txt (Not Quiet Exec, thank you @Brian Sutherland!):

<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Id="my-uid" Name="my_name" Language="1033" Version="1.11.5164" Manufacturer="company" UpgradeCode="my-uid">
        <Package Description="Test file in a Product" Comments="Simple test" InstallerVersion="200" Compressed="yes" />
        <Media Id="1" Cabinet="simple.cab" EmbedCab="yes" />
        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="ProgramFilesFolder" Name="PFiles">
                <Directory Name="my_folder" Id="MY_FOLDER">
                  <Component Id="CONFIGURE.BAT" DiskId="1" Guid="my-uid">
                         <File KeyPath="yes" Id="file_configure.bat" Name="configure.bat" Source="configure.bat" />
                  </Component>  
                </Directory>
            </Directory>
        </Directory>
        <Feature Id="MainFeature" Title="Main Feature" Level="1">
                   <ComponentRef Id="CONFIGURE.BAT" />
        </Feature>
        <UI />
        <UIRef Id="WixUI_Minimal" />
        <Property Id="CMD">
          <DirectorySearch Id="CmdFolder"  Path="[SystemFolder]" Depth="1">
            <FileSearch Id="CmdExe" Name="cmd.exe"  />
          </DirectorySearch>
        </Property>
        <Property Id="BATCHPARAMETER" Value="HAHIHUHEHO" Secure="yes" />
        <CustomAction Id="SetCustomActionData" Return="check" Property="BatchRun" Value="BATCHPARAMETER=[BATCHPARAMETER]" />
        <CustomAction Id="BatchRun" Property="CMD" Execute="deferred" Return="check" Impersonate="yes" ExeCommand="/c &quot;&quot;[#file_configure.bat]&quot; &quot;[BATCHPARAMETER]&quot;&quot;" />
        <InstallExecuteSequence>
            <Custom Action="SetCustomActionData" Before="BatchRun"></Custom>
            <Custom Action="BatchRun" After="InstallFiles">NOT Installed</Custom>
        </InstallExecuteSequence>  
    </Product>
</Wix>

configure.bat

I cannot find the way directly to the batch file in QuietExec by embedded syntax...(like ExeCommand="/c ""[#file_configure.bat]" "[BATCHPARAMETER]""" />)

setlocal
echo on

copy /Y C:\temp\hoge\hoge.txt C:\temp\hoge\hoge%date:~-10,4%%date:~-5,2%%date:~-2,2%.txt
echo %1 > C:\temp\hoge\hoge%date:~-10,4%%date:~-5,2%%date:~-2,2%.txt 2>&1
echo off
endlocal
exit /B 0
illuminate33
  • 117
  • 1
  • 9
-1

I had a very similar issue, ran a BAT file from WIX, as an EXE Package. On some computers the whole procedure failed error being Error 0x80070001: Process returned error: 0x1 Error 0x80070001: Failed to execute EXE package. Error 0x80070001: Failed to configure per-machine EXE package.

The fix was to remove the /b from the exit command, at the end of the BAT file. After this, everything suddenly worked!