gpt4 book ai didi

Wix:如何强行杀死进程/任务?

转载 作者:行者123 更新时间:2023-12-04 21:43:23 28 4
gpt4 key购买 nike

从使用 Wix 创建的 MSI 运行卸载时,我需要在尝试删除任何文件之前强行终止在后台运行的进程。主要应用程序由一个托盘图标组成,它反射(reflect)了 bg 进程监控本地 Windows 服务的状态(在 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" />

这个给了我一个不同的错误:

我正在考虑 build 一座雕像来纪念这个拒绝死亡的过程!!! ...或者认为应用程序端存在问题,我应该在其中添加诸如 Application.Exit(); 之类的东西。或 Environment.Exit(0);在 Program.cs 中的某行。

我可以在 Wix 或我的应用程序上做任何其他事情来尝试在卸载时成功关闭它吗?
谢谢!

最佳答案

我个人认为最适合您的选择是内置的 CloseApplication 方法,而不是您以前的选择。

您为此得到的错误(错误代码 2762)是因为您试图按立即顺序安排操作,但设置了 ElevatedCloseMessage="yes" 将其作为延迟操作触发。删除此属性或按延迟顺序安排它。

关于Wix:如何强行杀死进程/任务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16534676/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com