Architecture of Windows Services



Architecture of Windows Services

As shown in Figure, the Windows services architecture has five main components:

  • Windows Service Database

  • Service Control Manager

  • Windows Service Installer

  • Windows Services in Execution

  • Windows Service Controller

1. The Service Control Manager provides a unified way to control, configure, and access Windows services.

graphics/06fig01.gif

The following sections discuss each of these components.

Windows Service Database

The Windows service database stores information about all the installed services. This database is a part of the Windows Registry and is stored in the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services key. The Windows service database typically contains the following information for each Windows service:

  • Path to the executable file.

  • Security settings.

  • Startup parameters.

Even though you can directly manipulate the Windows service database by modifying the Windows Registry using the regedit command or through a program, it is not recommended that you do so. To ensure the integrity of the database, you should always manipulate the Windows service database through the interfaces that the SCM provides.

Service Control Manager (SCM)

SCM is a Windows component that maintains the Windows service database and provides a unified way to control, configure, and access these services. The SCM performs the following tasks:

  • Accepts requests to install and uninstall Windows services from the Windows service database.

  • Starts Windows services either on system startup or on demand.

  • Enumerates installed Windows services.

  • Maintains status information for running Windows services.

  • Transmits control messages (such as Start, Stop, Pause, and Continue) to running Windows services.

    NOTE

    Microsoft Management Console (MMC) MMC is an integrated administration environment for administrating Windows components and installed applications. By itself, MMC can't do much; however applications and Windows components provide snap-ins that integrate with the MMC and extend its Explorer-like user interface with menus, toolbars, property sheets, and wizards to perform specific administration tasks. All MMC snap-ins have a similar look and feel. This helps administrators to leverage their existing knowledge and quickly learn how to administer new applications.

    Windows Services on Remote Machines The SCM is started as a remote procedure call (RPC) server. This enables the Windows service control programs to manipulate services on remote machines.


  • Locks and unlocks the Windows service database.

Windows provides a generic interface to work with the SCM through the Services and Computer Management MMC (Microsoft Management Console) snap-ins. These MMC snap-ins can be accessed through the Administrative tool section of the Windows Control Panel. Some applications, such as IIS and SQL Server, provide their own MMC snap-ins to control and configure their services.

Windows Service Installer

A Windows service installer uses the SCM to install, uninstall, and repair a Windows service. The install, uninstall, and repair actions respectively create, delete, and update a Windows service record in the Windows service database.

While installing a service, the Windows service installer also stores information about how the service will be started. This information includes

  • A name that uniquely identifies the service in the Windows service database.

  • The account name and password under whose identity the service runs.

  • How the Windows service process is created (an independent process or a shared process).

  • How the service is started (automatically when Windows starts, manual start, disabled).

Windows Services in Execution

Just installing a service in the Windows service database is not sufficient to enable you to use the service's functionality. By default, a Windows service must be explicitly started. However, it is also possible to set up a service in such a way that the service is started automatically with Windows.

When the SCM starts a service, it attempts to create a Windows process for that service based on the information stored in the Windows service database. The SCM also sends a Start message to the service; this message invokes an associated handler in the service (if any) that specifies the processing to be done.

After a Windows service is started, it continues to run until it receives a pause message or a stop message. When a Windows service is paused, the process for the Windows service continues to exist, but the service does not listen to the requests from the client programs. On the other hand, when a Windows service is stopped, its process is terminated and the memory is reclaimed.

Windows Service Controller Program

The Windows service controller program uses the SCM to perform the following tasks:

  • Start a Windows service.

  • Stop a Windows service.

  • Pause a Windows service.

  • Resume the execution of a paused Windows service.

  • Query the Windows service database to retrieve the status for a Windows service.

  • Install a new Windows service in the Windows service database.

  • Uninstall an installed Windows service from the Windows service database.

  • Modify the configuration information for a Windows service.

You may question the need for the Windows service controller program when the Services MMC snap-in is already available to perform various control and administrative tasks for a Windows service. Although the Services MMC snap-in provides generic control and configuration options for Windows services, it cannot take care of the individual configuration requirements and customized user interface for each Windows service. For example, IIS provides an Internet Information Services snap-in in the MMC to provide a customized interface to administer the World Wide Web Publishing, the File Transfer Protocol (FTP) Publishing, Network News Transfer Protocol (NNTP), and the Simple Mail Transfer Protocol (SMTP) services.

REVIEW BREAK

  • Windows services are the applications that conform to the interface of the Windows Service Control Manager (SCM). SCM is the part of Windows that is responsible for managing Windows services.

  • Windows services are quite distinct from regular Windows applications. One of most apparent distinctions is that Windows services usually lack a GUI. In addition, a Windows service typically runs in the background and runs in its own process with a specific user identity.

  • Windows services must be installed in the Windows services database before they can be used. The Windows services database is a part of the Windows Registry. It is recommended that you not directly modify the database but rather modify the database through the SCM.