Understanding Windows Services



Understanding Windows Services

The Windows operating system provides a set of services that allow device manufacturers and software vendors to integrate their products with the operating system. These services include:

  • Kernel Services— The kernel is the core part of the operating system responsible for process, thread, and memory management. Kernel services enable devices and applications to interact with the kernel and use its functionality.

    NOTE

    Windows Service Application A Windows service application is a normal executable file (with an .exe extension) that contains the code for one or more Windows services.

    Support for Windows Services Windows services are available on Windows NT (where they are known as NT services), Windows 2000, Windows XP, and Windows Server 2003 operating systems. There is no support of Windows services on the Windows 95, Windows 98, or Windows ME operating systems.


  • Device Driver Services— A device driver controls and manages the hardware devices. Device driver services enable applications to work with devices.

  • Windows Services— Windows services enable operating system components and application programs to expose their functionality to other applications.

Kernel services and device driver services are used mostly by system programmers. As an application programmer, you'll be more interested in Windows services, and therefore Windows services are the focus of this chapter and Exam 70-320.

So what, exactly, is a Windows service? Precisely defined, a Windows service is a process that conforms to the interface rules of the Windows Service Control Manager (SCM). The SCM is a part of the Windows operating system that provides a unified way to control, configure, and access Windows services.

In general, a Windows service is a process that provides background services to other processes. Some typical examples of Windows services are World Wide Web Publishing, Print Spooler, Task Scheduler, Event Log, Plug and Play, and so on. Some common characteristics of Windows services are:

  • Conformance to SCM— Each Windows service must implement a set of well-known methods, which enable the service to communicate with the SCM. These well-known methods define how a Windows service should handle the SCM messages. Some common messages sent by SCM to a service are Start, Pause, Continue, and Stop. How these messages are handled depends totally on the service, because not all Windows services accept all messages. For example, the Event Log and Plug and Play Windows services do not accept Pause and Stop messages and therefore cannot be paused or stopped. In contrast, the Print Spooler Windows service can be started or stopped but cannot be paused.

  • Lack of User Interface— Although Windows services can interact with the desktop and provide a user interface, most services don't. Windows services perform system tasks that usually do not require any user interface. As an example, the job of IIS (Internet Information Services) is to serve the requested Web pages, and IIS does not require any user interface or desktop interaction to accomplish this job. IIS is launched when a computer is started and its process remains unseen by a Windows desktop user.

    NOTE

    Communication via the Event Log Windows services run in the background and generally do not provide a user interface. However, a Windows service may need to inform the user about an application state or an event in the environment. Most Windows services do so by writing informative messages in the event log.


  • Long-lived Process— Typically, a Windows service is started automatically when the computer is started and continues to live. Services can execute even when no user is logged on to the system. Most Windows services provide the functionality that enables them to be paused, resumed, started, or stopped.

  • Specific User Identity— Most Windows services run with System privileges. System is a special account that Windows uses to perform privileged operations. However, each Windows service can be launched with a specific user identity. This feature can restrict services to the permissions defined for an individual user. Consider a scenario where an administrator requires that a Windows service have access to only a limited set of directories on a file system. The administrator can easily accomplish this by following these two steps:

    1. Set up a user account with the set of permissions that the administrator wants the service to have.

    2. Configure the Windows service to run with the user identity that was created in step 1.

    EXAM TIP

    Currently Logged On User Most Windows services are started before a user logs on and they keep on running across multiple user sessions. Therefore, the functionality of a Windows service cannot depend on the permissions available to the currently logged on user. A Windows service always executes by using an assigned user identity that may be the same or different from the currently logged on user.


  • Separate Windows Process— A Windows service does not run in the process of the program that communicates with it. Instead, a Windows service runs in its own process. Sometimes, a Windows service can also share a process with another Windows service.

  • Special Installation Procedure— Unlike a Windows application, a Windows service cannot be started by just executing its .exe file. Instead, a Windows service requires a special installation procedure. This installation procedure registers the Windows service with the Windows Service Control Manager (SCM). The SCM provides varied functionality to control (such as to start, pause, and stop a service) and configure (such as setting up a service user account) the Windows services.