The Assembly Programming Master Book

What are services? For what purposes are they used, and how do you program them? All of these topics will be covered in this chapter.

Main Concepts and Control Functions

Services are special applications. Microsoft recommends that programmers implement server applications in the form of services. In the Windows operating system, most functions are delegated to services. A typical example is the Plug and Play service, which tracks all changes in computer hardware configuration and manages device installation and configuration. Another example of a service that runs on computers is the MSSQLSERVER service, which allows calls to the Microsoft SQL Server to be used in applications. The range of services is wide. To view this, start a special application called the Service Control Program (SCP). This program allows you to control the services running on your computer in the interactive mode. To start this application, click the Start button and select Settings Control Panel menu options. Then, double-click the Administrative Tools icon and start the SCP by double-clicking the Services icon. [i] The main window of this application is shown in Fig. 21.1.

Figure 21.1: The SCP allows you to Control Services in Microsoft Windows

To control a specific service, select the name of that service from the list and double-click it. The window displaying the properties of that service will open (Fig. 21.2). Note the following four buttons in the service properties window: Start, Stop, Pause, and Resume. Using these buttons, you can carry out the following operations over the chosen service:

Figure 21.2: The window that allows you to control a specific service

The Startup type list allows you to change the type of the service startup. The following options are available:

The system administrator can change the method used by the service to log on to the system. To achieve this, go to the Log On tab and choose the appropriate logon options for the service. By default, the LocalSystem account is used. Under this account, the service can carry out practically any operation in the system. If you don't want the service to log on under the name of the operating system, you can specify another account and password on this tab.

The Recovery tab allows you to define the system reaction if this service fails to start or terminates abnormally. The SCP allows you to specify the actions that the system should carry out in the case of the first, second, and all subsequent failures.

The Dependencies tab displays the list of all services that depend on this service, as well as all services, on which this service depends in its turn .

Windows services operate under the control of the SCM. All communications to the service are carried out through the SCM module. This module is implemented by the SERVICE.EXE program that resides in the system directory, starts automatically at system startup, and remains active until system shutdown.

The list of services installed in the system can also be found in the registry. To view this list, start the REGEDIT.EXE program and open the following registry key:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services

Fig. 21.3 shows the REGEDIT.EXE window with the list of installed services.

Figure 21.3: List of services installed in the system and displayed by the REGEDIT.EXE application

Note 

Do not change anything in the service settings or delete anything from the registry. However, if you are developing a custom service, this approach in some cases may provide the only possibility of debugging your application with minimum expenses.

[i] All material in this chapter relates only to the operating systems of the Windows NT family.

Категории