在 Wix MSI 中:卸载时终止进程
In Wix MSI: Killing a process upon uninstallation
我添加了一个自定义操作,当有人尝试使用以下代码在控制面板中使用 add/remove 卸载它时,应该使用 taskkill CMD 终止我的应用程序:
<Property Id="TASKKILL">
<DirectorySearch Id="SysDir" Path="[SystemFolder]" Depth="1">
<FileSearch Id="taskkillExe" Name="taskkill.exe" />
</DirectorySearch>
</Property>
<CustomAction Id="ServerKill" Property="TASKKILL" Execute="immediate" Impersonate="yes" Return="ignore" ExeCommand="/F /FI "IMAGENAME EQ App.exe""/>
<InstallExecuteSequence>
<Custom Action="ServerKill" After="FindRelatedProducts"/>
</InstallExecuteSequence>
但是这不起作用。如果有人可以告诉我如何修复它,甚至可以分享 better/easier 杀死我的应用进程的方法,我将不胜感激。
p.s
还尝试使用 cmd 使用 WMIC。那确实不起作用,因此安装本身根本没有完成。
也许您可以尝试 Util 架构中的 CloseApplication 功能:
http://wixtoolset.org/documentation/manual/v3/xsd/util/closeapplication.html
请在此处查看示例代码片段:https://sourceforge.net/p/wix/mailman/message/20186650/
更新:我 运行 进行了一些测试,该元素的工作方式与我的预期略有不同。您需要添加的第一件事是对 wixUtilExtension 文件的引用。在命令行上是:
candle -ext WiXUtilExtension Test.wxs
light -ext WixUtilExtension Test.wixobj
在Visual Studio中,我认为您只需将项目引用添加到WixUtilExtension.dll.
然后您只需将类似这样的内容添加到您的 wxs 源文件中:
<util:CloseApplication Id="CloseNotepad" Target="notepad.exe"
CloseMessage="yes" RebootPrompt="no">
</util:CloseApplication>
并将此添加到您的 wxs 文件的顶部:
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
看起来 Wix 会处理剩下的事情(自定义操作和 MSI 中的自定义 table 以及要终止的进程列表)。
这是我的完整测试文件:
<?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="*" UpgradeCode="12345678-1234-1234-1234-111111111111"
Name="Example Product Name" Version="0.0.1" Manufacturer="Example Company Name" Language="1033">
<Package InstallerVersion="200" Compressed="yes" Comments="Windows Installer Package"/>
<Media Id="1" Cabinet="product.cab" EmbedCab="yes"/>
<Directory Id="TARGETDIR" Name="SourceDir">
<Component Id="ApplicationFiles" Guid="*">
</Component>
</Directory>
<Feature Id="DefaultFeature" Level="1">
<ComponentRef Id="ApplicationFiles"/>
</Feature>
<util:CloseApplication Id="CloseNotepad" Target="notepad.exe" CloseMessage="yes" RebootPrompt="no"></util:CloseApplication>
</Product>
</Wix>
链接: 一些相关或边缘相关的链接,便于检索。
- Wix's util:CloseApplication extension doesn't seem to work
或者,计划在卸载时 运行 的简单 VBScript 应该可以完成这项工作:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'Notepad.exe'")
For Each objProcess in colProcessList
objProcess.Terminate()
Next
我添加了一个自定义操作,当有人尝试使用以下代码在控制面板中使用 add/remove 卸载它时,应该使用 taskkill CMD 终止我的应用程序:
<Property Id="TASKKILL">
<DirectorySearch Id="SysDir" Path="[SystemFolder]" Depth="1">
<FileSearch Id="taskkillExe" Name="taskkill.exe" />
</DirectorySearch>
</Property>
<CustomAction Id="ServerKill" Property="TASKKILL" Execute="immediate" Impersonate="yes" Return="ignore" ExeCommand="/F /FI "IMAGENAME EQ App.exe""/>
<InstallExecuteSequence>
<Custom Action="ServerKill" After="FindRelatedProducts"/>
</InstallExecuteSequence>
但是这不起作用。如果有人可以告诉我如何修复它,甚至可以分享 better/easier 杀死我的应用进程的方法,我将不胜感激。
p.s
还尝试使用 cmd 使用 WMIC。那确实不起作用,因此安装本身根本没有完成。
也许您可以尝试 Util 架构中的 CloseApplication 功能: http://wixtoolset.org/documentation/manual/v3/xsd/util/closeapplication.html
请在此处查看示例代码片段:https://sourceforge.net/p/wix/mailman/message/20186650/
更新:我 运行 进行了一些测试,该元素的工作方式与我的预期略有不同。您需要添加的第一件事是对 wixUtilExtension 文件的引用。在命令行上是:
candle -ext WiXUtilExtension Test.wxs
light -ext WixUtilExtension Test.wixobj
在Visual Studio中,我认为您只需将项目引用添加到WixUtilExtension.dll.
然后您只需将类似这样的内容添加到您的 wxs 源文件中:
<util:CloseApplication Id="CloseNotepad" Target="notepad.exe"
CloseMessage="yes" RebootPrompt="no">
</util:CloseApplication>
并将此添加到您的 wxs 文件的顶部:
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
看起来 Wix 会处理剩下的事情(自定义操作和 MSI 中的自定义 table 以及要终止的进程列表)。
这是我的完整测试文件:
<?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="*" UpgradeCode="12345678-1234-1234-1234-111111111111"
Name="Example Product Name" Version="0.0.1" Manufacturer="Example Company Name" Language="1033">
<Package InstallerVersion="200" Compressed="yes" Comments="Windows Installer Package"/>
<Media Id="1" Cabinet="product.cab" EmbedCab="yes"/>
<Directory Id="TARGETDIR" Name="SourceDir">
<Component Id="ApplicationFiles" Guid="*">
</Component>
</Directory>
<Feature Id="DefaultFeature" Level="1">
<ComponentRef Id="ApplicationFiles"/>
</Feature>
<util:CloseApplication Id="CloseNotepad" Target="notepad.exe" CloseMessage="yes" RebootPrompt="no"></util:CloseApplication>
</Product>
</Wix>
链接: 一些相关或边缘相关的链接,便于检索。
- Wix's util:CloseApplication extension doesn't seem to work
或者,计划在卸载时 运行 的简单 VBScript 应该可以完成这项工作:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'Notepad.exe'")
For Each objProcess in colProcessList
objProcess.Terminate()
Next