【问题标题】:In Wix MSI: Killing a process upon uninstallation在 Wix MSI 中:卸载时终止进程
【发布时间】:2016-08-29 13:15:02
【问题描述】:

我添加了一个自定义操作,当有人尝试使用控制面板中的添加/删除使用以下代码卸载它时,它应该使用 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 &quot;IMAGENAME EQ App.exe&quot;"/>

<InstallExecuteSequence>
    <Custom Action="ServerKill" After="FindRelatedProducts"/>   
</InstallExecuteSequence>

但是这不起作用。如果有人能告诉我如何解决它,甚至分享一个更好/更简单的方法来杀死我的应用程序进程,我将不胜感激。

p.s
还尝试使用 cmd 使用 WMIC。这真的没有用,安装本身也因此根本没有完成。

【问题讨论】:

    标签: wix uninstallation windows-installer


    【解决方案1】:

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

    查看示例代码 sn-p: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 中的自定义表以及要终止的进程列表)。


    这是我的完整测试文件:

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

    链接:一些相关或边缘相关的链接,便于检索。

    【讨论】:

    • 嗨,感谢重播检查,由于某些未知原因,我无法定义 CloseApplication 元素。我收到以下消息:Setup.wxs(35):错误 CNDL0200:产品元素包含未处理的扩展元素“util:CloseApplication”。请确保已提供“schemas.microsoft.com/wix/UtilExtension”命名空间中元素的扩展名。 WixUI_InstallDirNoLicense.wxs light.exe:错误 LGHT0093:在提供的中间体列表中找不到条目部分。 “产品”类型的预期部分。
    • 我在上面的答案中添加了一些细节。
    【解决方案2】:

    另外,一个计划在卸载时运行的简单 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-20
      • 2010-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多