在 Wix MSI 中:卸载时终止进程 [英] In Wix MSI: Killing a process upon uninstallation

查看:45
本文介绍了在 Wix MSI 中:卸载时终止进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加了一个自定义操作,当有人尝试使用以下代码在控制面板中使用添加/删除来卸载它时,应该使用 taskkill CMD 杀死我的应用程序:

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 &quot;IMAGENAME EQ App.exe&quot;"/>

<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.

ps
还尝试使用 cmd 使用 WMIC.这确实不起作用,因此安装本身根本没有完成.

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.

推荐答案

也许您可以尝试 Util 架构中的 CloseApplication 功能:http://wixtoolset.org/documentation/manual/v3/xsd/util/closeapplication.html

Perhaps you can try the CloseApplication feature from the Util schema: http://wixtoolset.org/documentation/manual/v3/xsd/util/closeapplication.html

查看示例代码片段:https://sourceforge.net/p/wix/mailman/message/20186650/

更新:我进行了一些测试,这个元素的工作方式与我的预期略有不同.您需要添加的第一件事是对 wixUtilExtension 文件的引用.在命令行上是:

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

Visual Studio 中,我认为您只需添加对 WixUtilExtension.dll 的项目引用.

In Visual Studio I think you simply add a project reference to WixUtilExtension.dll.

然后你只需将这样的东西添加到你的 wxs 源文件中:

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>

并将其添加到 wxs 文件的顶部:

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">

看起来 Wix 负责其余的工作(自定义操作和 MSI 中的自定义表以及要杀死的进程列表).

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>

这篇关于在 Wix MSI 中:卸载时终止进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆