WIX在InstallExecution序列中调用批处理文件

时间:2012-03-05 08:48:27

标签: batch-file wix invoke

我是WIX的新手,我正在尝试从我的WIX安装程序调用批处理文件。 MyBatch.bat包含一个简单的文本文件副本,从c:\到D:\

我无法调用批处理文件。以下是我的代码。

请帮帮我。

  <?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 个答案:

答案 0 :(得分:6)

这对我有用。

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

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

答案 1 :(得分:2)

看来你用错误的工具解决了你的问题。如果要复制的文件是您的应用程序的一部分,您应该在Component内创建File。否则,如果您只需复制目标系统上已存在的某个外部文件,则应创建CopyFile元素,并将其嵌套在Component元素下。

答案 2 :(得分:1)

我同意Yan,你以错误的方式解决了你的任务。


对于批处理文件,它们不像.exe一样自行执行,它是cmd.exe,它读取bat文件并逐行执行。

要运行批处理文件,您应该以这种方式运行它:

cmd.exe /c batch.bat

答案 3 :(得分:1)

添加您的CustomAction定义,如下所示。如果你没有从bat文件中返回任何内容,请确保Return =“ignore”。

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

同样在installExecuteSequence序列中,在InstallFinalize

之前添加操作
<InstallExecuteSequence>
    <Custom Action="RunBat" Before="InstallFinalize">
        NOT (REMOVE~="ALL")
    </Custom>
</InstallExecuteSequence>