WiX:在RemoveExistingProducts之前停止服务或运行提升的CustomAction以在RemoveExistingProducts之前停止进程

Sem*_*nit 7 windows-installer wix

我在重大升级时遇到了问题.安装程序包含一项服务,在升级时我得到一个弹出窗口,说明需要重新启动才能完成安装过程.

为了防止这种行为,我实际上只需要在执行RemoveExistingProducts(而不是InstallValidate)之前停止服务.

在MajorUpgrade放置后InstallInitialize和所述封装具有InstallPrivileges="elevated".

我有两个案例:


案例1:服务由ServiceInstallvia 安装

<Component Id="myservice_Service" Guid="*">
            <File Id="myservice.exe" KeyPath="yes" Vital="yes"
                  Source="SourceDir\bin\myservice.exe"/>
            <ServiceInstall Id="myservice_ServiceInstall" Type="ownProcess"
                            Vital="yes" Name="myservice" DisplayName="myservice Service"
                            Description="myservice Service" Start="auto" Account=".\LocalSystem"
                            ErrorControl="ignore" Interactive="no" Arguments="--run"/>
            <ServiceControl Id="myservice_ServiceControl" Name="myservice" Wait="yes" Stop="uninstall"/>
        </Component>
Run Code Online (Sandbox Code Playgroud)

在ServiceControl不停止服务之前InstallValidate被调用.即使说Stop ="both".所以弹出窗口出现了.请注意,安装程序不会启动该服务.

我发现的合理帖子(摘录):


案例2:服务由a安装CustomAction(有一些原因,为什么不做通过ServiceInstall).在这种情况下,我必须调用可执行文件来停止服务("myservice.exe --stop").为此,它变得棘手,因为由于ICE63,不允许调度CustomAction之前RemoveExistingProducts调用.那么,我怎么能实现这个呢?

到目前为止,我已阅读过以下帖子:

bootstrapper exe是没有选择的,因为我需要生成一个普通的MSI.

我在这里找到了类似的未解答的问题:Wix安装程序问题:为什么RestartManager将服务标记为RMCritical而不是RMService

Phi*_*lDW 2

InstallValidate 之后 ServiceControl 的顺序无关紧要。如果在 InstallValidate 中检测到某个服务的文件正在使用情况,但该服务位于 ServiceControl 表中并在卸载时停止,则 Windows 会相当合理地推迟任何文件正在使用情况,以查看实际发生的情况。如果您将其从 ServiceControl 中取出,您将失去这个潜在有用的功能。请注意,您可以独立于 ServiceInstall 使用 ServiceControl - 它们没有绑定在一起,因此如果服务可以与 ServiceControl 配合良好,则不一定需要运行 exe 来停止服务。

造成这种情况的一个常见原因就是服务行为不当。wait=yes 不会永远等待,根据文档只有 30 秒。因此,服务必须响应指示其停止的控制消息。即使服务“停止”,也不意味着该进程已经消失,只是它不再作为服务运行。如果需要一段时间才能真正终止该进程,那么 Windows 别无选择,只能显示正在使用的文件。这些事情很难调试,因为时间问题通常是这样,但如果是我,我会仔细检查服务关闭代码。

另请注意,在升级场景中您可能需要 stop=both。如果 InstallValidate(在您即将进行的升级中)在 ServiceControl 中没有看到安装停止,并且有文件正在使用中,那么您将遇到文件正在使用的问题。InstallValidate不会提前查看RemoveExistingProducts何时可能运行,然后在另一个MSI中查找可能阻止文件使用的ServiceControl停止点。