2015-04-28 250 views
0

我想安裝後運行多個exe文件。此代碼創建單個msi,部署這兩個exe,但運行第一個。 我還沒有在整個互聯網上找到它的一個例子。這是我的代碼(不要介意「把guid放在這裏」):如何使用wix安裝程序運行多個安裝的exe文件?

<?xml version="1.0" encoding="UTF-8"?> 
<<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> 
    <Product Id="*" 
      UpgradeCode="PUT-GUID-HERE" 
      Version="1.0.0.0" 
      Language="1033" 
      Name="My Application Name" 
      Manufacturer="My Manufacturer Name">  
    <Package InstallerVersion="300" Compressed="yes"/> 
    <Media Id="1" Cabinet="myapplication.cab" EmbedCab="yes" /> 

    <Directory Id="TARGETDIR" Name="SourceDir"> 
     <Directory Id="ProgramFilesFolder"> 
      <Directory Id="APPLICATIONROOTDIRECTORY" Name="My Application Name"/> 
     </Directory> 
    </Directory> 

    <DirectoryRef Id="APPLICATIONROOTDIRECTORY"> 
     <Component Id="Installs" Guid="PUT-GUID-HERE"> 
      <File Id="myapplication.exe" Source="MySourceFiles\MyApplication.exe" KeyPath="yes" Checksum="yes"/> 
     <File Id="myapplication2.exe" Source="MySourceFiles\MyApplication.exe2" KeyPath="yes" Checksum="yes"/> 
     </Component> 
    </DirectoryRef> 

    <Feature Id="MainApplication" Title="Main Application" Level="1"> 
     <ComponentRef Id="Installs" /> 
    </Feature> 

    <UI> 
     <UIRef Id="WixUI_Minimal" /> 
     <Publish Dialog="ExitDialog" 
      Control="Finish" 
      Event="DoAction" 
      Value="LaunchApplication">WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1 and NOT Installed</Publish> 
    </UI> 
    <Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOXTEXT" Value="Launch My Application Name" /> 


    <Property Id="WixShellExecTarget" Value="[#myapplication.exe]" /> 
    <CustomAction Id="LaunchApplication" 
     BinaryKey="WixCA" 
     DllEntry="WixShellExec" 
     Impersonate="yes" /> 
    </Product> 
</Wix> 

但它只安裝第一個exe完成安裝。想法? 最好的問候。

回答

0

你可以做2次:首先設置屬性「WixShellExecTarget」,然後調用「WixShellExec」。即嘗試用自定義操作代替設置該屬性:

<UI> 
    <UIRef Id="WixUI_Minimal" /> 

    <!-- set property and launch the first exe --> 
    <Publish Dialog="ExitDialog" Control="Finish" Event="DoAction" Value="PrepareLaunchApplication1">WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1 and NOT Installed</Publish> 
    <Publish Dialog="ExitDialog" Control="Finish" Event="DoAction" Value="LaunchApplication1">WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1 and NOT Installed</Publish> 

    <!-- set property and launch the second exe --> 
    <Publish Dialog="ExitDialog" Control="Finish" Event="DoAction" Value="PrepareLaunchApplication2">WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1 and NOT Installed</Publish> 
    <Publish Dialog="ExitDialog" Control="Finish" Event="DoAction" Value="LaunchApplication2">WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1 and NOT Installed</Publish> 
</UI> 
<Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOXTEXT" Value="Launch My Application Name" /> 

<CustomAction Id="PrepareLaunchApplication1" Property="WixShellExecTarget" Value="[#myapplication.exe]" /> 
<CustomAction Id="LaunchApplication1" 
    BinaryKey="WixCA" 
    DllEntry="WixShellExec" 
    Impersonate="yes" /> 

<CustomAction Id="PrepareLaunchApplication2" Property="WixShellExecTarget" Value="[#myapplication2.exe]" /> 
<CustomAction Id="LaunchApplication2" 
    BinaryKey="WixCA" 
    DllEntry="WixShellExec" 
    Impersonate="yes" /> 

如果你想要運行程序依次等待第二個退出並檢查它的退出代碼,你可以使用「ExeCommand」而不是「WixShellExec」。如果你不關心退出代碼,你需要相應地配置ExeCommand(檢查文檔)。

<UI> 
    <UIRef Id="WixUI_Minimal" /> 

    <Publish Dialog="ExitDialog" Control="Finish" Event="DoAction" Value="LaunchApplication1">WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1 and NOT Installed</Publish> 
    <Publish Dialog="ExitDialog" Control="Finish" Event="DoAction" Value="LaunchApplication2">WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1 and NOT Installed</Publish> 
</UI> 

<CustomAction Id="LaunchApplication1" FileKey="myapplication1.exe" ExeCommand="" Impersonate="yes" /> 
<CustomAction Id="LaunchApplication2" FileKey="myapplication2.exe" ExeCommand="" Impersonate="yes" /> 
+0

謝謝,工作。有沒有辦法讓exe依次運行,而不是同時運行? –

+0

我已編輯帖子。如果您想等到程序結束,您可以使用ExeCommand而不是WixShellExec。 – Nikolay

+0

太棒了,我也可以用它來運行MSI文件嗎? –

1

組件不能有多個keypath。每個EXE文件都應該是每個Windows Installer組件規則中它自己的組件的關鍵路徑。

我看不出會有什麼啓動。 [#myapplication.exe]是一個格式化的表達式,它在ConstFinalize之後纔有效。您需要一個適當的SetProperty自定義操作。您需要多一個也可以一遍又一遍地爲每個要啓動的EXE調用LaunchApplication。或者創建一個自定義EXE,唯一的目的是啓動其他人。

相關問題