我正在添加系统变量,然后我想执行自定义操作,这取决于这些变量。正确添加变量,但脚本正在退出(因为此时变量尚未存在),请使用“安装后文件”来保存。这是我的代码:
<?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 "unzip.exe nssm-2.24.zip -d "%TANGO_ROOT%\bin" "" 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 :(得分:0)
Windows Installer中的环境变量存在两个常见问题:
设置它们时,它们不会自动显示正在运行的程序,因为Windows Installer在安装结束之前不会发送“环境变量已更改”广播消息。如果你运行一个程序,它将获取新的值。
没有理由让任何正在运行的进程获取它们,除非它们有一个消息循环并准备处理(我认为)WM_WININICHANGE消息并重新加载环境。
因此,没有任何自定义操作会获取新变量,因为它们尚未广播到系统并且已“提交”。是的,最好找到另一种方法将数据传递给程序。
答案 1 :(得分:0)
即使Phil说:&#34;在安装过程中未设置系统变量: Windows Installer不会发送环境变量已更改广播消息,直到安装结束,当您正在读取注册表时,它们存储在变量(&#34; DIRR&#34;在此示例中)中:
<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 ****"[DIRR]bin"****" Return="ignore" />
这些方式您的批处理文件可以访问系统变量,尽管事实上尚未在系统中设置。 希望这有助于:)