MSI:在 InstallValidate 期间卸载时如何停止服务 - 这是否可行? [英] MSI: How a Service is stopped on uninstall during InstallValidate - could that work anyway?

查看:18
本文介绍了MSI:在 InstallValidate 期间卸载时如何停止服务 - 这是否可行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,如果服务在 WiX 项目文件中被标记为 Remove="uninstall" Stop="uninstall",具体如何以及何时停止.

我为什么要问:卸载时,重新启动管理器无法识别或正确处理该服务,从而导致重新启动对话框".

我将调试器附加到服务并意识到,它从未被尝试过停止 - 至少,不是通过注册的 ControlHandler.我在猜测,它将以与执行sc stop servicename"相同的方式停止或通过服务对话框停止它.服务本身是用 C++ 编写的,控制处理程序由 RegisterServiceCtrlHandler 注册,它在两种情况下都可以正常工作.停止服务时调用处理程序.不是这样,如果它是通过 MSI 停止/卸载的.

顺便说一下,正如 jbudreau 在 编辑 2:(ID 9324 与屏幕截图不同,取自不同尝试的日志文件)

MSI (s) (BC:38) [16:46:14:141]: RESTART MANAGER: 检测到 ID 为 9324、友好名称为---as.exe"、类型为 RmCritical 和状态 1 保存正在使用的文件 [s].MSI (s) (BC:38) [16:46:14:141]:RESTART MANAGER:检测到一个关键应用程序保存了正在使用的文件 [s],因此需要重新启动.

编辑 3:日志文件:uninstall.log - 日志文件太大,无法在此处发布(30000 个字符)局限性).

解决方案

InstallValidate 不会停止服务 - 这是由 StopServices 操作完成的.InstallValidate 试图找出正在使用的文件(使用重新启动管理器)并显示正在使用的文件对话框.就服务而言,它会忽略 ServiceControl 表中具有卸载时停止"设置的服务正在使用的任何文件.如果您想确保服务完全停止,请使用 wait="yes".这是一个标准的停止服务控制处理程序调用.

如果服务触发了一堆仍在运行的进程,那么这只是一个普通的文件使用问题,与服务无关.这些进程需要关闭调用(来自服务?)或者它们应该与重启管理器集成,这种事情:http://www.codeproject.com/Articles/772868/Restart-Manager-Support-For-Windows-Application

如果进程响应 Windows 消息,WiX util CloseApplication 应将其关闭.

我要指出,您的 WiX 中可能只是存在一个错误,其中 ServiceControl 中命名的服务不正确.由于您可以控制任何服务(不仅仅是您正在安装/卸载的服务),因此无需检查名称是否与您的服务或任何其他服务相对应.如果您从未看到服务控制停止被调用,这是最简单的解释.

I want to know, how and when in concrete a service is tried to stop if it's marked as Remove="uninstall" Stop="uninstall" in the WiX Project File.

Why I'm asking: On uninstalling, the service is not recognized or handled correctly by the RESTART MANAGER resulting in the "restart dialog".

I attached the debugger to the service and realized, that it's never been tried to be stopped - at least, not via the registered ControlHandler. I was guessing, that it will be stopped in the same manner as executing "sc stop servicename" or by stopping it via the Services-Dialog. The service itself is written in C++ and the control handler is registerd by RegisterServiceCtrlHandler which works quite normally with the both outlined cases. The handler is invoked when stopping the service. Not so, if it's stopped/uninstalled via the MSI.

By the way, as stated by the answer of jbudreau in Wix Installer Problem: Why does RestartManager mark Service as RMCritical and not RMService can a service ever been stopped in the InstallValidate section if the service is running as LocalSystem? In InstallValidate, the uninstall-process is not elevated yet.

Some explanation of how the process of stopping a LocalSystem service is working on uninstall would be great!

Thanks in advance!

EDIT: Here is my service definition with ServiceInstall and ServiceControl:

        <DirectoryRef Id="BINDIR">
        <!-- the service -->
        <Component Id="myProgramsvc.exe" Guid="1f64c03f-26ea-47ba-985c-2a566afffffa">
            <File Id="myProgramsvc.exe" KeyPath="yes" Vital="yes"
                  Source="SourceDir\bin\myProgramsvc.exe"/>
            <ServiceInstall Id="MyProgramSvc" Type="ownProcess"
                            Vital="yes" Name="MyProgramSvc" DisplayName="Test MyProgram Service"
                            Description="Test MyProgram Service" Start="auto" Account=".\LocalSystem"
                            ErrorControl="normal" Interactive="no" Arguments="--run"/>
            <ServiceControl Id="MyProgramSvc" Name="MyProgramSvc" Wait="yes" Remove="uninstall" Stop="uninstall" Start="install"/>
        </Component>
    </DirectoryRef>

and the process hierarchy, where the RestartManager is complaining about the ----as.exe (PID: 4312): EDIT 2: (the id 9324 is different from the screenshot, took from the logfile of a differenty try)

MSI (s) (BC:38) [16:46:14:141]: RESTART MANAGER: Detected that application with id 9324, friendly name '---as.exe', of type RmCritical and status 1 holds file[s] in use.
MSI (s) (BC:38) [16:46:14:141]: RESTART MANAGER: Did detect that a critical application holds file[s] in use, so a reboot will be necessary.

EDIT 3: The Logfile: uninstall.log - the logfile is too large for posting here (30000 chars limitation).

解决方案

InstallValidate doesn't stop services - that's done by the StopServices action. InstallValidate is what tries to figure out what files are in use (with Restart Manager) and show a files-in-use dialog. Where services are concerned, it ignores any files in use by services that are in the ServiceControl table with a "stop at uninstall" setting. If you want to be sure that the service completely stops, use wait="yes". It's a standard stop service control handler call.

If the service fires off a bunch of processes that remain running then it's just an ordinary files-in-use issue and services are not relevant. Those processes need a shut-down call (from the service?) or they should integrate with Restart Manager, this kind of thing : http://www.codeproject.com/Articles/772868/Restart-Manager-Support-For-Windows-Application

If a process responds to windows messages the WiX util CloseApplication should shut it down.

I'll point out that you may simply have a bug in your WiX where the service named in your ServiceControl is incorrect. Since you can control any service (not just one you're installing/uninstalling) there is no check that the name corresponds to your service or any other. If you never see the service control stop being called this is the simplest explanation.

这篇关于MSI:在 InstallValidate 期间卸载时如何停止服务 - 这是否可行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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