In-depth: How .NET managed services interact with the ServiceControlManager (SCM) [Kim Hamilton]

.NET managed services are based on NT services, and both need to know how to interact with the ServiceControlManager (SCM) to remain responsive. For managed services, many of the complexities of interacting with the SCM are handled for you by System.ServiceProcess.ServiceBase; however, there are some you still need to be aware of. I’ll summarize the…

9

Change in System.ServiceProcess shutdown is coming in 3.5 RTM [Inbar Gazit]

In all current versions of the Framework we do not close the actual service when we get a shutdown request from the OS. Instead we just call OnShutdown and hope that the user has overridden this method and called Stop() themselves. We found out that many developers didn’t know they had to do that and…

8

Installing a Managed Service with a Custom Name [Robert Villahermosa]

Title: Installing a Managed Service with a Custom Name Author: Robert Villahermosa (RobVi)   An interesting customer question came to my attention a few weeks ago.  The customer had created a managed service, and was installing it with a custom name that was provided at install time by the user.  I’ve seen several customer applications…

1

Code: Installing a Managed Service with a Custom Name [Robert Villahermosa]

using System; using System.ServiceProcess; using System.Configuration.Install; using System.ComponentModel; using System.IO; public class SimpleService : ServiceBase { public static void Main() { ServiceBase.Run(new SimpleService()); } public SimpleService() { CanPauseAndContinue = true; //Here we are setting a service name to show you don’t need a custom name if you don’t want one //This gets overriden in this…

0

Installing a Managed Service with a Custom Name (Part 4 of 4) [Robert Villahermosa]

Bringing it all together Ok, that’s it for the explanation – let’s see how to actually run all this and watch it work. Here are the steps to follow: 1.)   Create a simple service that we want to install 2.)   Create a ProjectInstaller class specifying some defaults and handing custom install/uninstall events 3.)   Compile this…

0

Installing a Managed Service with a Custom Name (Part 3 of 4) [Robert Villahermosa]

What happened to specifying a custom name? Ahh, I haven’t forgotten – this post was created to see how to let the user choose their own custom service name.  Notice how I’ve hooked up two eventhandlers in my Project Installer code.  BeforeInstall gets called at execution time prior to the service being installed and BeforeUninstall…

0

Installing a Managed Service with a Custom Name (Part 2 of 4) [Robert Villahermosa]

The Installer class Now that we have our simple service to install, let’s take a look at how we can install it.    Custom installers in the .NET Framework all derive from the Installer class.  There are several methods that you can override in this class, but we won’t go into detail about these here…

6

Installing a Managed Service with a Custom Name (Part 1 of 4) [Robert Villahermosa]

An interesting customer question came to my attention a few weeks ago.  The customer had created a managed service, and was installing it with a custom name that was provided at install time by the user.  I’ve seen several customer applications that do this.  Upon uninstall, they were encountering a failure – this seemed bizarre,…

6