Chapter 23

Windows Services

Windows Services are programs that can be started automatically at boot time without the need for anyone to log on to the machine.

In this chapter, you learn:

  • The architecture of Windows Services, including the functionality of a service program, a service control program, and a service configuration program
  • How to implement a Windows Service with the classes found in the System.ServiceProcess namespace
  • Installation programs to configure the Windows Service in the registry
  • How to write a program to control the Windows Service using the ServiceController class
  • How to troubleshoot Windows Service programs
  • How to react to power events from the operating system

The first section explains the architecture of Windows Services. You can download the code for this chapter from the Wrox Web site at

What Is a Windows Service?

Windows Services are applications that can be automatically started when the operating system boots. They can run without having an interactive user logged on to the system and do some processing in the background. For example, on a Windows Server, system networking services should be accessible from the client without a user logging on to the server. On the client system, services are useful as well; for example, to get a new software version from the Internet or to do some file cleanup on the local disk. You can configure a Windows Service to be run from a specially configured user account or from the system user account — ...

Get Professional C# 2008 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.