stop/delete windows service on uninstall

Comments

2 comments

  • Avatar
    wojciechka

    You can use Event Viewer tool to check details of the error. If there is a note about error to stop the service anywhere in the logs?

    Can you stop the service manually going to services panel? (services.msc)

    The error may be that service itself refused to stop.

    If the service does not stop, InstallBuilder is unable to delete it since it is still running.

  • Avatar
    DevHopeful_2012

    Ran into the same problem, where some services were active and/or undergoing development and didn't properly respond to the stop command. There really isn't anything that you can do about it from the uninstaller perspective, as wojciechka indicated.

    So, I created a custom function to uninstall a service. The function handles the varying service actions to stop and remove per platform, and, most importantly, exits the uninstaller if any service fails to stop. The following is just the stop action:

    <stopWindowsService>
        <displayName>${displayName}</displayName>
        <serviceName>${serviceName}</serviceName>
        <abortOnError>1</abortOnError>
        <customErrorMessage>Unable to complete the uninstallation because we could not stop the Windows Service - ${displayName}.  Please stop this service manually and restart the uninstallation.</customErrorMessage>
        <delay>10000</delay>
        <showMessageOnError>1</showMessageOnError>
        <onErrorActionList>
            <!-- Abort due to unable to stop service -->
            <logMessage>
                <text>Aborting uninstall.  Unable to complete the uninstallation because we could not stop the Windows Service - ${displayName}.</text>
            </logMessage>
            <exit exitCode="1"/>
        </onErrorActionList>
    </stopWindowsService>
    

    Then, the preUninstallationActionList just calls

    <uninstallService serviceName="some_service" displayName="some_name"/>
    

    for each service in your distribution.

Please sign in to leave a comment.