如何使用MSI包卸载topshelf服务?

时间:2021-10-06 07:16:23

I have several services developed with topshelf that are installed using an MSI created in InstallShield (using basic MSI). We install them using a custom action passing the install parameter. When it comes to uninstall, we use a custom action passing the uninstall parameter (we also have custom actions that start and stop as appropriate). All of this is working, but the user is presented with a dialog asking them to shut down those services otherwise a reboot may be required otherwise. If, however, the user elects to continue anyway, our custom action runs, stopping and uninstalling the service.

我有几个使用topshelf开发的服务,这些服务是使用在InstallShield中创建的MSI安装的(使用基本的MSI)。我们使用传递install参数的自定义操作来安装它们。在卸载时,我们使用自定义操作传递uninstall参数(我们还有适当的自定义操作启动和停止)。所有这些都有效,但是会向用户显示一个对话框,要求他们关闭这些服务,否则可能需要重新启动。但是,如果用户选择继续,我们的自定义操作将运行,停止和卸载服务。

I have been unable to move the stop action high enough in the execute sequence to avoid the dialog without causing a not in transaction error.

我无法在执行序列中将停止操作移动得足够高以避免对话而不会导致不存在事务错误。

Is there some way I can get rid of that dialog?

有什么方法可以摆脱那个对话吗?

1 个解决方案

#1


2  

To stop the service with a custom action you'd need to have it before InstallValidate, which means it has to be immediate, so it gets tricky if the install is canceled or fails because then you leave the system with a stopped service.

要使用自定义操作停止服务,您需要在InstallValidate之前使用它,这意味着必须立即执行,因此如果安装被取消或失败,则会变得棘手,因为这会使系统停止服务。

The real solution to this is that you're supposed to install services with the ServiceInstall element, and stop/start/delete them with the ServiceControl element. At uninstall, if Windows Installer sees that you're going to stop the service (with ServiceControl) then it doesn't do a FilesInUse dialog.

对此的真正解决方案是您应该使用ServiceInstall元素安装服务,并使用ServiceControl元素停止/启动/删除它们。在卸载时,如果Windows Installer发现您要停止服务(使用ServiceControl),则它不会执行FilesInUse对话框。

So the short answer is that you may not need a custom action at all. The ServiceControl element can be used to stop and start all services (not just ones being installed with ServiceInstall) so if you do a ServiceControl element to stop your service at uninstall it might solve the problem. In the long term I'd get away from command line installs and use ServiceInstall.

所以简短的回答是你可能根本不需要自定义动作。 ServiceControl元素可用于停止和启动所有服务(不仅仅是使用ServiceInstall安装的服务),因此如果您执行ServiceControl元素以在卸载时停止服务,则可能会解决问题。从长远来看,我将远离命令行安装并使用ServiceInstall。

#1


2  

To stop the service with a custom action you'd need to have it before InstallValidate, which means it has to be immediate, so it gets tricky if the install is canceled or fails because then you leave the system with a stopped service.

要使用自定义操作停止服务,您需要在InstallValidate之前使用它,这意味着必须立即执行,因此如果安装被取消或失败,则会变得棘手,因为这会使系统停止服务。

The real solution to this is that you're supposed to install services with the ServiceInstall element, and stop/start/delete them with the ServiceControl element. At uninstall, if Windows Installer sees that you're going to stop the service (with ServiceControl) then it doesn't do a FilesInUse dialog.

对此的真正解决方案是您应该使用ServiceInstall元素安装服务,并使用ServiceControl元素停止/启动/删除它们。在卸载时,如果Windows Installer发现您要停止服务(使用ServiceControl),则它不会执行FilesInUse对话框。

So the short answer is that you may not need a custom action at all. The ServiceControl element can be used to stop and start all services (not just ones being installed with ServiceInstall) so if you do a ServiceControl element to stop your service at uninstall it might solve the problem. In the long term I'd get away from command line installs and use ServiceInstall.

所以简短的回答是你可能根本不需要自定义动作。 ServiceControl元素可用于停止和启动所有服务(不仅仅是使用ServiceInstall安装的服务),因此如果您执行ServiceControl元素以在卸载时停止服务,则可能会解决问题。从长远来看,我将远离命令行安装并使用ServiceInstall。