Due to the fact that services have no desktops, they usually do not interact with the users. But there has to be a way for controlling and managing these services. Service Control Manager does just that.
The SCM, a part of the windows kernel, is the one that controls the lifetime of the service. Any process that needs to be started and stopped like a service has to register itself with the SCM. The SCM then takes care of when to launch the service and when to stop it. The SCM holds a list of all the installed services, when they should be started, whether they should be allowed to interact with the desktop, etc.
The administrator can control services by sending control requests to them (e.g. "start service", "stop service", etc.) via the SCM. This is done using the Services applet of the control panel; double-clicking on the icon brings up the Services window, which lists all the services in the SCM database. Another utility to view the services running is WinMsd.exe. Combining the functionalities available in these two utilities, with an additional capability to control and configure the services on remote computers is Service Controller (SC.exe). This utility is not pre-installed with windows and has to be downloaded to every computer that needs it. All these utilities use the SCM to communicate with the services.
The SCM maintains its database of services installed in the system in the registry. Each service has an entry in the following key:
Here, the Service Name is the name of the service used by the SCM. The service name seen in the Services applet is different from this one. This is a unique name used internally by the SCM. The corresponding name of each service which is displayed in the applet is stored in the key Display Name inside the Service Name key.
Each service can run by logging on as either a Local System or particular user account. Also the services can be enabled or disabled for specific hardware profile. Each service could either run independently or it will depend on some other service(s). The list of services each service depends on will be maintained by the SCM. All these information could be seen from the Services applet by looking at the properties of each service. Other than the list of services a particular service depends on, a list of services that depend on this service can also be seen.
When a service fails, the SCM can decide what action to take. These can be specified directly through the Service applet. The possible actions are:
· Restart the service
· Run a particular file
· Reboot the computer
· Take no action
By default the response for a failure is to take no action. If the service fails for the second time too, one of these actions can be set. For subsequent failures, another action could be assigned.
Building a service is a little complicated in the sense that a certain steps have to be followed to successfully build and install a service. Prior to .NET, the only efficient way to build a .NET was by building it in C++/ VC++. It was complicated and had various issues to be considered while doing it. But .NET has changed the way the services were build. With its Framework Base Classes available as a part of the .NET Framework, building services were made easy. By taking advantage of the object oriented capability of .NET, various tasks needed to build a service has been greatly simplified by encapsulating them inside various classes and including them as a part of the .NET Framework Base Classes. These base classes in the .NET Framework take care of the system-level interfacing.