WiX: terminate before RemoveExistingProducts OR run elevated CustomAction to stop the process before RemoveExistingProducts

I have a problem with a major upgrade. The installer turns on the service, and during the upgrade I received a pop-up message stating that a reboot was required to complete the installation process.

To prevent this behavior, I just need to stop the service before RemoveExistingProducts (rather InstallValidate ) is executed.

MajorUpgrade is placed after InstallInitialize , and the package has InstallPrivileges="elevated" .

I have two cases:


Case 1: Service is installed by ServiceInstall through

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

ServiceControl does not stop the service until InstallValidate called. Even when they say Stop = "both". Thus a popup appears. Please note that the service is not started by the installer.

Reasonable posts I found (excerpt):


Case 2: The service is installed using CustomAction (there are reasons why it is also not possible to execute through ServiceInstall ). In this case, I have to call the executable to stop the service ("myservice.exe --stop"). This becomes difficult for this, because ICE63 is not allowed to schedule a CustomAction before calling RemoveExistingProducts . So how can I achieve this?

So far I have read posts like:

The boot exe has no option, since I need to create a simple MSI.

I found the same unanswered problem: Wix installer problem: why RestartManager marks Service as RMCritical and not RMService

+6
source share
2 answers

Sequencing the ServiceControl after InstallValidate does not matter. If a file usage situation is detected for a service in InstallValidate, but the service is in the ServiceControl table, which must be stopped when it is deleted, then Windows fairly reasonably postpones any file situation to see what is actually happening. If you select it from ServiceControl, you will lose this potentially useful function. Please note that you can use ServiceControl independently of ServiceInstall - they are not related to each other, so you do not need to run exe to stop the service if it can work well with ServiceControl.

A common cause of this situation is simple unacceptable maintenance. Wait = yes will not wait forever, only 30 seconds according to the documentation. Therefore, the service must respond to a control message telling it to stop. Even when the service is β€œstopped”, which does not mean that the process has left, only that it no longer works as a service. If some time is required for the final completion of the process, then Windows has no alternative but to show the files in use. These things are difficult to debug, because there are usually synchronization issues, but if it were me, I would carefully study the service shutdown code.

Note that you may need to stop = both in the update script. If InstallValidate (in your inbound update) does not see the installation stopping in ServiceControl, and there are files that are being used, you will get this file problem. InstallValidate does not look forward when RemoveExistingProducts may appear, and then switch to another MSI to stop the ServiceControl, which may prevent the use of files.

+2
source

Solution for case 2:

 <DirectoryRef Id='INSTALLDIR'> <Component Id='StopService' Guid='{0913D365-8EC0-424A-939E-0F04E99D2ACA}' KeyPath='yes'> <ServiceControl Id='StopServiceControl' Name='ServiceName' Stop='uninstall' Wait='yes'/> </Component> </DirectoryRef> 

In this case, the FileInUse dialog box does not appear.

0
source

Source: https://habr.com/ru/post/989727/


All Articles