在WIX中添加系统变量后执行自定义操作



我正在添加系统变量,然后我想执行自定义操作,这取决于这些变量。变量正在正确添加,但是脚本正在退出(因为当时尚未存在变量),depSite我正在使用" AFTARD ALLTACT FILES"的事实。这是我的代码:

<?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="SoftwarecorpTango"
                      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>

我做错了什么吗?问候

Windows安装程序中的环境变量有两个一般问题:

  1. 设置时,它们不仅会自动出现在运行程序中,因为Windows Installer不会发送"环境变量已更改"广播消息,直到安装结束为止。如果您在此之后运行程序,它将拾取新值。

  2. 除非有消息循环并准备处理(我认为)WM_WININICHANGE消息并重新加载环境,否则没有理由将其接管它们。

因此,您的自定义操作都不会拾取新变量,因为它们尚未被广播到系统并"承诺"。是的,最好找到将数据传递给程序的另一种方法。

菲尔没有错。但这是我的解决方案,如果有人会遇到同样的问题:

正如Phil所说:"安装过程中未设置系统变量:Windows Installer直到安装结束之前都不会发送环境变量更改了广播消息,当您读取注册表时,它们在变量内存储(在此示例中" dirr"):

<Property Id="DIRR">
        <RegistrySearch Id="aaa" Root="HKCU"
                          Key="SoftwarecorpTango"
                          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" />

尽管批处理文件尚未在系统中设置,但批处理文件可以访问系统变量。希望这会有所帮助:)

最新更新