2017-09-25 46 views
0

我正在添加系統變量,然後我想執行自定義操作,這取決於這些變量。變量正在被正確添加,但是腳本正在退出(因爲那時變量還沒有),所以我正在使用「安裝文件之後」的事實。這是我的代碼:在Wix中添加系統變量後執行自定義操作

<?xml version="1.0" encoding="UTF-8"?> 
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" 
     xmlns:util="http://schemas.microsoft.com/wix/UtilExtension"> 

    <Product Id="*" Name="DataBaseds_Service_Installer" Language="1033" Version="1.0.0.0" Manufacturer="" UpgradeCode="3875ce89-3886-4cbf-b132-01f947ac7a08"> 
     <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" /> 

     <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." /> 
     <MediaTemplate EmbedCab="yes" /> 
    <CustomAction Id="NssmUnzip" Directory="INSTALLFOLDER" Execute="deferred" Impersonate="no" ExeCommand="cmd.exe /c &quot;unzip.exe nssm-2.24.zip -d &quot;%TANGO_ROOT%\bin&quot; &quot;" Return="ignore" /> 
    <CustomAction Id="Tango_db" Directory="INSTALLFOLDER" Execute="deferred" Impersonate="no" ExeCommand="[INSTALLFOLDER]create-tangodb.bat" Return="ignore" /> 
    <CustomAction Id ="Baseds_Service" Directory="INSTALLFOLDER" Execute="deferred" Impersonate="no" ExeCommand="[INSTALLFOLDER]Tango-DataBaseds.bat" Return="ignore" /> 
    <CustomAction Id="UninstallService" Directory="INSTALLFOLDER" Execute="deferred" Impersonate="no" ExeCommand="[INSTALLFOLDER]Remove_Baseds_Service.bat" Return="ignore" /> 

    <InstallExecuteSequence> 
     <Custom Action="NssmUnzip" After="InstallFiles">NOT Installed</Custom> 
     <Custom Action="Tango_db" After="NssmUnzip">NOT Installed</Custom> 
     <Custom Action="Baseds_Service" After="Tango_db">NOT Installed</Custom> 
     <Custom Action="UninstallService" After="InstallInitialize"> Installed and Not REINSTALL</Custom>  
    </InstallExecuteSequence> 

    <Property Id="DIRR"> 
    <RegistrySearch Id="aaa" Root="HKCU" 
         Key="Software\corp\Tango" 
         Name="Directory" 
         Type="directory"/> 
    </Property> 
     <Feature Id="ProductFeature" Title="DataBaseds_Service_Installer" Level="1"> 
     <ComponentRef Id="MYSQL_Path"/> 
     <ComponentRef Id="MYSQL_USER"/> 
     <ComponentRef Id="MYSQL_PASSWORD"/> 
      <ComponentGroupRef Id="Components" /> 
     </Feature> 

     <Directory Id="TARGETDIR" Name="SourceDir"> 
      <Directory Id="ProgramFilesFolder"> 
       <Directory Id="INSTALLFOLDER" Name="DataBaseds_Service_Installer" /> 
      </Directory> 
     </Directory> 

    <ComponentGroup Id="Components" Directory="INSTALLFOLDER"> 

     <Component Id="NSSM" Guid="54CEB76C-6974-4071-96E9-EF5AD1937BD4"> 
     <File Source="nssm-2.24.zip" KeyPath="yes" /> 
     <File Source="Tango-DataBaseds.bat" KeyPath="no"/> 
     <File Source="Remove_Baseds_Service.bat" KeyPath="no"/> 
     <File Source="create-tangodb.bat" KeyPath="no"/> 
     </Component> 
     <Component Id="unzip" Guid="E10EE17A-AA5A-416B-82DF-37532281116C"> 
     <File Source="unzip.exe" KeyPath="yes"/> 
     </Component> 

    </ComponentGroup> 
    <DirectoryRef Id="TARGETDIR"> 
     <Component Id="MYSQL_USER" Guid="D05C8155-8421-4AEB-9A19-5016DAFAED19"> 
     <Environment Id="MYSQL_USER" Name="MYSQL_USER" Value="root" Permanent="no" Part="last" Action="set" System="yes" /> 
     </Component> 
     <Component Id="MYSQL_PASSWORD" Guid="222C7887-1E4D-4DC2-B429-A3F18F707FA3"> 
     <Environment Id="MYSQL_PASSWORD" Name="MYSQL_PASSWORD" Value="tango" Permanent="no" Part="last" Action="set" System="yes" /> 
     </Component> 
     <Component Id="MYSQL_Path" Guid="34D14695-1803-4D7E-AD65-3C9011D019CE"> 
     <Environment Id="PATH" Name="PATH" Value="[DIRR]bin" Permanent="no" Part="last" Action="set" System="yes" /> 
     </Component> 

    </DirectoryRef> 

    </Product> 
</Wix> 

我做錯了什麼? 問候

+0

檢查此答案https://stackoverflow.com/questions/4515905/set-environment-variable-before-running-a-custom-action-in-wix有可能是一種更好的方法你可以實現這一點。 –

+0

不,這不完全是我的情況:( 我可以做兩個獨立的msi文件,一個用於變量,另一個用於自定義活動,但它是過度殺傷,除非我必須要 –

+0

纔可以修改腳本所以你可以傳入環境變量值?假設你知道他們,因爲你在安裝過程中設置它們。 –

回答

0

有與Windows安裝程序的環境變量兩種通用的問題:

  1. 當他們設置他們不只是自動顯示爲正在運行的程序,因爲Windows安裝程序不會發送「環境變量已經改變「廣播消息,直到安裝結束。如果你運行一個程序後,它會拿起新的值。

  2. 沒有理由讓任何正在運行的進程接受它們,除非它們有一個消息循環並準備處理(我認爲)WM_WININICHANGE消息並重新加載環境。

因此,您的自定義操作都不會接收新變量,因爲它們尚未被廣播到系統中並「已提交」。是的,最好找到另一種將數據傳遞給程序的方式。

0

菲爾沒有錯。 但這裏是我的解決方案,如果有人永遠不會有同樣的問題:

即使菲爾說:「系統變量不是安裝過程中設置: Windows安裝程序不會發送環境變量已經改變廣播消息直到在安裝結束時,他們都存儲在變量(在這個例子中「DIRR」),當您正在閱讀的註冊表:

<Property Id="DIRR"> 
     <RegistrySearch Id="aaa" Root="HKCU" 
          Key="Software\corp\Tango" 
          Name="Directory" 
          Type="directory"/> 
     </Property> 

所以,你可以運行一個腳本,並通過他們的說法:

<CustomAction Id="Tango_db" Directory="INSTALLFOLDER" Execute="deferred" Impersonate="no" ExeCommand="[INSTALLFOLDER]create-tangodb.bat ****&quot;[DIRR]bin&quot;****" Return="ignore" /> 

這些方式可以使批處理文件訪問系統變量,儘管系統中尚未設置它。 希望這可以幫助:)