我们在 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="Installation" Language="1033" Version="1.0.0.0">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine">
</Package>
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<Media Id="1" Cabinet="cab1.cab" EmbedCab="yes" />
<Feature Id="ProductFeature" Title="MyInstallation" Level="1">
<ComponentGroupRef Id="ProductComponents" />
<ComponentGroupRef Id="MyComponents" />
</Feature>
<util:Group Id="Users" Name="Users"/>
<CustomAction Id="InstallMyService"
Directory="INSTALLFOLDER"
ExeCommand="[INSTALLFOLDER]bin\my-service.bat install"
Execute="deferred"
Impersonate="no"
Return="check"/>
<CustomAction Id="SetEnvironmentVariable" BinaryKey="ActionLib" DllEntry="SetEnvironmentVariableForNewUser" />
<Binary Id='ActionLib' SourceFile='..\InstallerActionLibrary\bin\Release\InstallerActionLibrary.CA.dll' />
<CustomAction Id="StartMyService"
Directory="INSTALLFOLDER"
ExeCommand="[INSTALLFOLDER]bin\my-service.bat start"
Execute="deferred"
Impersonate="no"
Return="asyncWait"/>
<InstallExecuteSequence>
<Custom Action="InstallMyService" After="InstallFiles"/>
<Custom Action="SetEnvironmentVariable" After="InstallMyService"/>
<Custom Action="StartMyService" After="SetEnvironmentVariable"/>
</InstallExecuteSequence>
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="CommonAppDataFolder">
<Directory Id="Company" Name="Company">
<Directory Id="App" Name="Product">
<Directory Id="INSTALLFOLDER" Name="Service" />
</Directory>
</Directory>
</Directory>
</Directory>
</Fragment>
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<Component Id="NewUser" Guid="{12345678-ABCD-1234-ABCD-987654321FED}">
<CreateFolder />
<util:User Id="CIUSER" CreateUser="yes" UpdateIfExists="no" Name="SERVICEUSER" PasswordNeverExpires="yes" Password="********">
<util:GroupRef Id="Users" />
</util:User>
</Component>
</ComponentGroup>
</Fragment>
</Wix>
但是,自定义操作之一 SetEnvironmentVariable
需要在设置用户后在文件底部的片段中运行。而这不会发生。 SetEnvironmentVariable
失败,因为找不到用户。
InstallExecuteSequence
中给出的序列在 InstallFiles
发生后开始。我试图找到一个更合适的位置来开始序列,使用给定的列表 here 。我试过 PublishProduct
,结果是一样的。
有没有办法在自定义操作运行之前添加用户?
最佳答案
@zett42 的建议很好。但是,还是没有解决问题。
解决方案是错误地使用 Execute="deferred"
。所有自定义操作的执行应该设置为:
Execute="commit"
提交
表示自定义操作将在成功完成安装脚本后运行(在安装结束时)。
将执行类型更改为提交并且有效。
关于windows - 在 Wix 中运行自定义操作之前添加用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42913498/