问题
I added a custom action that should kill my application using taskkill CMD when someone tries to uninstall it using the add/remove in the control panel using the following code :
<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>
However this does not work. If someone can tell me how to fix it or even share a better/easier way to kill my app process I would be grateful.
p.s
also tried to use WMIC using cmd. That really didn't work and the installation itself did not finish at all because of this.
回答1:
Perhaps you can try the CloseApplication feature from the Util schema: http://wixtoolset.org/documentation/manual/v3/xsd/util/closeapplication.html
See here for an example code snippet: https://sourceforge.net/p/wix/mailman/message/20186650/
UPDATE: I ran some tests and this element works a little differently from what I expected. The first thing you need to add is the reference to the wixUtilExtension file. On the command line this is:
candle -ext WiXUtilExtension Test.wxs
light -ext WixUtilExtension Test.wixobj
In Visual Studio I think you simply add a project reference to WixUtilExtension.dll.
Then you simply add something like this to your wxs source file:
<util:CloseApplication Id="CloseNotepad" Target="notepad.exe"
CloseMessage="yes" RebootPrompt="no">
</util:CloseApplication>
And add this at the top of your wxs file:
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
It looks like Wix takes care of the rest (custom actions and a custom table in your MSI with the list of processes to kill).
Here is my full test file:
<?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>
回答2:
Alternatively a simple VBScript scheduled to run on uninstall should do the job:
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
来源:https://stackoverflow.com/questions/39207260/in-wix-msi-killing-a-process-upon-uninstallation