success - Windows service does not stop and not deleted on uninstall(Wix)




wix.com login (2)

I've seen a few related questions on stackoverflow that relate to this one, but none of them seem to address the specific behavior I'm observing.

I have a Windows Service defined as follows in a Wix 3.0 .wxs file.

<Component Id='Service' Guid='3c658a54-b236-11e0-bbf6-039615e482ae' >

    <File Id='ServiceEXE' Name='m_agent_service.exe'
          Vital='yes' Source='..\m_agent_service.exe'
          KeyPath='yes' />

    <ServiceInstall Id='MerakiServiceInstall'
        Vital='yes'
        Name='MerakiPCCAgent' DisplayName='Meraki Client Insight Agent $(env.VERSION)' Description="Meraki Client Insight Monitoring and Management Service"
        Type='ownProcess' Interactive='no' Start='auto' ErrorControl='normal'>
    </ServiceInstall>

    <ServiceControl Id='MerakiServiceControl'
        Name='MerakiPCCAgent'
        Start='install' Stop='both' Remove='uninstall'
        Wait='yes' />
</Component>

When I install the .MSI, the service is installed and running. Great.

When I then uninstall (either by running msiexec /x or using the Add/Remove Software from the Control Panel), the service keeps on running and is not removed. In fact, the log of the service itself tells me that none of the service shutdown code has been invoked. (When I use "sc stop", for example, I do see service shutdown code running cleanly.)

Here are some salient parts from the msiexec /x uninstall log:

MSI (s) (14:04) [11:33:54:692]: 1 application(s) had been reported to have files
 in use.
Info 1603. The file C:\Program Files\Meraki\PCC Agent 1.0.67\m_agent_service.exe
 is being held in use by the following process: Name: m_agent_service, Id: 3120,
 Window Title: '(not determined yet)'.  Close that application and retry.
MSI (c) (40:78) [11:33:54:692]: File In Use: -m_agent_service- Window could not
be found. Process ID: 3120
MSI (c) (40:78) [11:33:54:692]: No window with title could be found for FilesInUse

[...]

Action start 11:33:57: UnpublishFeatures.
MSI (s) (14:04) [11:33:57:379]: Doing action: StopServices
MSI (s) (14:04) [11:33:57:379]: Note: 1: 2205 2:  3: ActionText
Action ended 11:33:57: UnpublishFeatures. Return value 1.
Action start 11:33:57: StopServices.
MSI (s) (14:04) [11:33:57:379]: Doing action: DeleteServices
MSI (s) (14:04) [11:33:57:379]: Note: 1: 2205 2:  3: ActionText
Action ended 11:33:57: StopServices. Return value 1.
Action start 11:33:57: DeleteServices.
MSI (s) (14:04) [11:33:57:379]: Doing action: RemoveFiles

[...]

MSI (s) (14:04) [11:33:57:645]: Product: Meraki Client Insight Agent -- Removal
completed successfully.

MSI (s) (14:04) [11:33:57:645]: Windows Installer removed the product. Product N
ame: Meraki Client Insight Agent. Product Version: 1.0.67. Product Language: 103
3. Removal success or error status: 0.

https://code.i-harness.com


Check the verbose log file and ensure the Component is being changed. It is possible the Feature is turned off or a Component/Condition is causing the Component to be skipped.


Oh dear, whilst on the loo I had a brainwave and I think I have fixed it myself after all – sorry for the post! I think I shall explain what fixed it though in case any other beginners following the same Wix book as me run into the same issue.

Basically, I changed the Guid on my component, reinstalled, uninstalled and it all worked again. (I take on board that changing Guids may not be best practice, but this worked for me.)

To elaborate, I think there was actually no problem at all with my installer – the problem was on the PC I was using to test the installation. My first attempt at installing this windows service was done with no ServiceControl element, just the ServiceInstall element. I then tested the install, and it worked, but the service didn’t remove itself on uninstall, obviously. I then manually stopped and uninstalled the service from my PC using Services.msc.

I then read the next section of my book, realised I also needed a ServiceControl element, created it and re-tried the installer – but I was using the same Guid. The uninstall still didn’t work correctly and I assumed I’d done something wrong in my installer, hence the post above.

What I’m guessing had happened is that the previous install, using the same Guid but without the ServiceControl element, caused my PC to get corrupted somehow and prevented the new uninstaller from completing properly.

Let this be a lesson to me – never test your installer on your own PC! One of those rules I fully understand and happily ignore, till it bites me :)