我尝试使用 WiX Installer 在 cmd 中运行自定义命令。
我使用 Product.wxs 中的包含文件,该文件在整个安装过程中正确使用。
我有 3 个自定义操作,其中 2 个工作正常。似乎不起作用的是:
<CustomAction Id='AddDefaultDomain'
Directory='TARGETDIR'
Impersonate="no"
Execute="immediate"
ExeCommand="C:\windows\system32\inetsrv\appcmd.exe set config /section:basicAuthentication /defaultLogonDomain:[%USERDOMAIN] /commit:apphost"
Return="asyncNoWait" />
安装程序正确运行,当我通过 cmd 窗口调用 AppCmd 并在 cmd 中复制->粘贴“ExeCommand”并执行它时,它工作正常。
也许这很简单,但现在我不明白为什么它不起作用。
感谢所有帮助。
完整包含文件
<?xml version="1.0" encoding="utf-8"?>
<Include>
<!-- Create Scheduled Task -->
<InstallExecuteSequence>
<Custom Action="CreateScheduledTaskGoogleService" After="InstallFiles">NOT Installed</Custom>
<Custom Action="CreateScheduledTaskGoogleServiceId" After="CostFinalize">NOT Installed</Custom>
<!-- Add Defualt DOmain -->
<Custom Action="AddDefaultDomain" After="CostFinalize">NOT Installed</Custom>
</InstallExecuteSequence>
<CustomAction Id="CreateScheduledTaskGoogleService" Return="check" Impersonate="no" Execute="deferred" BinaryKey="WixCA" DllEntry="CAQuietExec" />
<CustomAction Id="CreateScheduledTaskGoogleServiceId" Property="CreateScheduledTaskGoogleService" Execute="immediate" Value=""[SystemFolder]SCHTASKS.EXE" /CREATE /TN "ActaNet Control - Google Sync" /XML "[INSTALLFOLDERPROGRAMFILESGOOGLE]ScheduledTask.xml"" />
<!-- DOES NOT SEEM TO BE WORKING! -->
<CustomAction Id='AddDefaultDomain'
Directory='TARGETDIR'
Impersonate="no"
Execute="immediate"
ExeCommand="C:\windows\system32\inetsrv\appcmd.exe set config /section:basicAuthentication /defaultLogonDomain:[%USERDOMAIN] /commit:apphost"
Return="asyncNoWait" />
<!-- Delete Scheduled Task -->
<InstallExecuteSequence>
<Custom Action="TaskDeleteGoogleService" Before="CreateScheduledTaskGoogleService">REMOVE="ALL"</Custom>
</InstallExecuteSequence>
<CustomAction Id="TaskDeleteGoogleService" Return="ignore" Execute="deferred" Directory="TARGETDIR" Impersonate="no" ExeCommand="SCHTASKS.EXE /DELETE /TN "ActaNet Control - Google Sync" /F" />
</Include>
我要做的第一件事就是确认命令确实正在执行。使用 Process Monitor 等工具来确认这一点。
完成此操作后,我将查看该命令是否正在修改目标系统上的某些内容,而这需要提升权限才能执行此操作。如果是这样,我会将 Execute 属性的值更改为“延迟”并查看它是否有效。您似乎正在尝试使用立即模式自定义操作来更改目标系统上的某些内容。将操作标记为延迟还需要您将该操作放置在“InstallInitialize”和“InstallFinalize”之间。
在您目前的情况下,您正在尝试以立即模式启动 exe。立即模式会模拟登录用户,因此在 UAC 环境中,任何修改目标系统的自定义操作都可能会失败。
首先,将自定义操作的“执行”更改为延迟,因为您没有立即类型的系统权限。
其次,使用日志记录来查看安装过程中发生的情况。使用下面的 concole 命令将在 YourInstaller.msi 所在的同一文件夹中创建安装过程的日志文件:
msiexec -i YourInstaller.msi -l*v log.txt
您可以通过自定义操作名称在结果 log.txt 文件中找到,以查看当安装程序尝试执行它时会发生什么。