【发布时间】:2013-05-14 03:33:37
【问题描述】:
当从使用 Wix 创建的 MSI 运行卸载时,我需要在尝试删除任何文件之前强制终止正在后台运行的进程。主应用程序包含一个托盘图标,它反映了监视本地 Windows 服务的 bg 进程的状态(在 C# 上制作,尽管这可能不那么相关)。
我首先尝试了以下方法:
<File Id='FooEXE' Name='Foo.exe' Source='..\Source\bin\Release\Foo.exe' Vital='yes' />
...
<InstallExecuteSequence>
<Custom Action="CloseTray" Before="InstallValidate" />
</InstallExecuteSequence>
...
<CustomAction Id="CloseTray" ExeCommand="-exit" FileKey="FooEXE" Execute="immediate" Return="asyncWait" />
确认应用程序关闭对话框后托盘图标立即关闭,但卸载完成后 Foo.Exe 任务仍出现在 taskmgr 上。此外,还给出了以下错误消息:
这就是为什么,然后我尝试了这个:
<InstallExecuteSequence>
<Custom Action="Foo.TaskKill" Before="InstallValidate" />
</InstallExecuteSequence>
...
<CustomAction Id="Foo.TaskKill" Impersonate="yes" Return="asyncWait" Directory="WinDir" ExeCommand="\System32\taskkill.exe /F /IM Foo.exe /T" />
得到同样的结果后,尝试:
<Property Id="QtExecCmdLine" Value='"[WinDir]\System32\taskkill.exe" /F /IM Foo.exe'/>
...
<InstallExecuteSequence>
<Custom Action="MyProcess.TaskKill" Before="InstallValidate" />
</InstallExecuteSequence>
...
<CustomAction Id="MyProcess.TaskKill" BinaryKey="WixCA" DllEntry="CAQuietExec" Execute="immediate" Return="ignore"/>
我从这里获取的示例:How to kill a process from WiX
最近所有其他方法都失败了,我也尝试了这个但没有成功:
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
...
<InstallExecuteSequence>
<Custom Action="WixCloseApplications" Before="InstallValidate" />
</InstallExecuteSequence>
...
<util:CloseApplication Id="CloseFoo" CloseMessage="yes" Description="Foo is still running!" ElevatedCloseMessage="yes" RebootPrompt="yes" Target="Foo.exe" />
这个给了我一个不同的错误:
我正在考虑建造一座雕像来纪念这个拒绝死亡的过程!!! ...无论是那个还是认为应用程序端存在问题,我应该在其中添加类似 Application.Exit();或 Environment.Exit(0);在 Program.cs 中的某行。
我可以在 Wix 或我的应用程序上做些什么来尝试在卸载时成功关闭它吗? 谢谢!
【问题讨论】:
标签: wix wix3.5 wix-extension