4

I want to know, how and when in concrete a service is tried to stop if it's marked as Remove="uninstall" Stop="uninstall" in the WiX Project File.

Why I'm asking: On uninstalling, the service is not recognized or handled correctly by the RESTART MANAGER resulting in the "restart dialog".

I attached the debugger to the service and realized, that it's never been tried to be stopped - at least, not via the registered ControlHandler. I was guessing, that it will be stopped in the same manner as executing "sc stop servicename" or by stopping it via the Services-Dialog. The service itself is written in C++ and the control handler is registerd by RegisterServiceCtrlHandler which works quite normally with the both outlined cases. The handler is invoked when stopping the service. Not so, if it's stopped/uninstalled via the MSI.

By the way, as stated by the answer of jbudreau in Wix Installer Problem: Why does RestartManager mark Service as RMCritical and not RMService can a service ever been stopped in the InstallValidate section if the service is running as LocalSystem? In InstallValidate, the uninstall-process is not elevated yet.

Some explanation of how the process of stopping a LocalSystem service is working on uninstall would be great!

Thanks in advance!

EDIT: Here is my service definition with ServiceInstall and ServiceControl:

        <DirectoryRef Id="BINDIR">
        <!-- the service -->
        <Component Id="myProgramsvc.exe" Guid="1f64c03f-26ea-47ba-985c-2a566afffffa">
            <File Id="myProgramsvc.exe" KeyPath="yes" Vital="yes"
                  Source="SourceDir\bin\myProgramsvc.exe"/>
            <ServiceInstall Id="MyProgramSvc" Type="ownProcess"
                            Vital="yes" Name="MyProgramSvc" DisplayName="Test MyProgram Service"
                            Description="Test MyProgram Service" Start="auto" Account=".\LocalSystem"
                            ErrorControl="normal" Interactive="no" Arguments="--run"/>
            <ServiceControl Id="MyProgramSvc" Name="MyProgramSvc" Wait="yes" Remove="uninstall" Stop="uninstall" Start="install"/>
        </Component>
    </DirectoryRef>

and the process hierarchy, where the RestartManager is complaining about the ----as.exe (PID: 4312): process hierarchy of the service EDIT 2: (the id 9324 is different from the screenshot, took from the logfile of a differenty try)

MSI (s) (BC:38) [16:46:14:141]: RESTART MANAGER: Detected that application with id 9324, friendly name '---as.exe', of type RmCritical and status 1 holds file[s] in use.
MSI (s) (BC:38) [16:46:14:141]: RESTART MANAGER: Did detect that a critical application holds file[s] in use, so a reboot will be necessary.

EDIT 3: The Logfile: uninstall.log - the logfile is too large for posting here (30000 chars limitation).

Community
  • 1
  • 1
Semonit
  • 379
  • 3
  • 14

1 Answers1

2

InstallValidate doesn't stop services - that's done by the StopServices action. InstallValidate is what tries to figure out what files are in use (with Restart Manager) and show a files-in-use dialog. Where services are concerned, it ignores any files in use by services that are in the ServiceControl table with a "stop at uninstall" setting. If you want to be sure that the service completely stops, use wait="yes". It's a standard stop service control handler call.

If the service fires off a bunch of processes that remain running then it's just an ordinary files-in-use issue and services are not relevant. Those processes need a shut-down call (from the service?) or they should integrate with Restart Manager, this kind of thing : http://www.codeproject.com/Articles/772868/Restart-Manager-Support-For-Windows-Application

If a process responds to windows messages the WiX util CloseApplication should shut it down.

I'll point out that you may simply have a bug in your WiX where the service named in your ServiceControl is incorrect. Since you can control any service (not just one you're installing/uninstalling) there is no check that the name corresponds to your service or any other. If you never see the service control stop being called this is the simplest explanation.

PhilDW
  • 20,260
  • 1
  • 18
  • 28
  • See edit. The ServiceControl element contains the right name. – Semonit Apr 29 '16 at 08:04
  • It may be worth doing the uninstall and creating a verbose log to see what it says about StopServices. msiexec /x {product guid} /l*vx – PhilDW Apr 29 '16 at 17:14
  • Already did that - see edit. I added the log-output to the question. The thing is not about StopServices. That stoppes the application and terminates all processes (within seconds). Anyway, it's scheduled AFTER InstallValidate. The InstallExecuteSequence contains InstallValidate with 1400 and StopServices with 1900. The RESTART MANAGER is complainig about the ---as.exe. Is it necessary that all child processes of the service have to include some special thing, so that the restart manager knows, that it's been terminated by the service if it's stopped? – Semonit May 01 '16 at 14:54
  • You must have missed my comment where I said that InstallValidate doesn't raise file-in-use events for services marked to be stopped later by StopServices so "AFTER" is irrelevant. A service is not stopped by InstallValidate, as your post subject says, InstallValidate checks for file-in-use situations before starting the install transaction. – PhilDW May 01 '16 at 17:02
  • P.S. The entire log might be useful; also your post says PID 9324 in the log fragment but 2324 in the process display; is that --as.exe your service executable or something else? Can't tell from the log, the display and your service name what the exact details are; also, the OP says the SCH is not called by the MSI uninstall, but your comment says .."that StopServices stops the application and terminates all processes" which seem to be contradictory statements. I've tried to give an explanation of how InstallValidate/StopServices work, but not specifics without a clear pic of the details. – PhilDW May 01 '16 at 22:24
  • Yes, thats the point. InstallValidate checks for file-in-use stiuations and is reporting this situation which I need to prevent. I don't want the "You need to restart your computer..."-Dialog. If I say OK on the dialog, the Service is stopped and all processes are terminated. In the Edit I indicated, that the PID is not the same as in the image because I've needed to create the logfile again - and the service was restarted in the meanwhile getting another PID – Semonit May 02 '16 at 08:27
  • I added the whole log-output to the post - BUT please note, I replaced the productName with "myProgram". So ---as.exe is named "myProgramas.exe". (Whereby ---as.exe was already named differently) – Semonit May 02 '16 at 08:27
  • Another note: If the RestartManager is disabled ``. The application is uninstalled without any complaints - but disabling the RestartManager seems to be an uncertain solution. – Semonit May 02 '16 at 08:52
  • The process with the file open is myprogramas.exe, but the service is myprogramsvc.exe, so as far as I can tell it's nothing to do with services but with myprogramas.exe. – PhilDW May 12 '16 at 18:23
  • the myprogramas.exe is a subprocess of myprogramsvc.exe which will be terminated in service shutdown. What and how in any case the executable myprogramas.exe (or any other subprocess) needs to implement or do in order to not cause this problems? – Semonit May 30 '16 at 12:22