2017-09-25 112 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" /> 

这些方式可以使批处理文件访问系统变量,尽管系统中尚未设置它。 希望这可以帮助:)