Automatic account creation is now enabled. Captcha authentication required for account creation and editing unless you are trusted here.

Services and WiX

From WiX Wiki at MindCapers

Jump to: navigation, search

You should be able to just schedule the service to be stopped and no file-in-use error should occur.


<Component...>
    <File ... Name="MyService.exe" ></File>
    <ServiceControl Id="MyService" Name="MyService.exe" Stop="uninstall" Remove="uninstall" Wait="yes">
        <ServiceArgument> /d "[INSTALLDIR]EF.G"</ServiceArgument>
    </ServiceControl>
</Component>

I still get "file-in-use" popup when uninstall.(Stop service is happened after CostFinilize, InstallValidate)

---

You could have a race condition (we did). I don't know if it's Windows Installer or a WiX Custom Action that stops services but, it appears that it continues when the service controller reports that the service is stopped. The service controller reports a service as stopped when the service successfully responds to a stop request (i.e. a ServiceBase based class' OnStop method completes successfully). But, the files are in-use until the process exits. If your OnStop method just starts the shutdown and then returns, you have a problem. Your OnStop method should start the shutdown of the service threads and then wait for them to complete before it exits.

---

...and the point of that Wait="Yes" is that it translates to Wait=1 in the ServiceControl table so that it does really wait for the Service to finish, not just for the SCM to respond.

---

There is one big gotcha when comparing the ServiceInstaller class in .NET with ServiceInstall in WiX. The ServiceInstaller actually does two things:

- Creates the Windows service in the Service Control Manager (SCM)
- Creates an event source associated with the application event log for the service to write messages to

As such, ServiceInstall only takes care of 1/2 of the required tasks. To create the event source, you could either use the new support for that in WiX 3 that Bob added last year or just write the appropriate registry entries manually using <Registry>.

However, it is totally possible to install a Windows service implemented in .NET using ServiceInstall. There is nothing particularly fancy that the ServiceInstaller class does that ServiceInstall doesn't do from the actual SCM perspective.

If there are any installer classes defined in the assemblies that get installed with the service, those basically just would not get used in the WiX-based deployment. As many of us have been suggesting, that is a good thing, as those are best avoided when there are better alternatives.

---

http://commandwindows.com/taskkill.htm

Personal tools