Introduction to Windows Services

I l @ ve RuBoard

Windows services are background processes that need to run for an extended period of time. This is usually the entire time the computer is up and running ”although a user with the appropriate permissions can control the lifetime of the service if necessary. Examples of common Windows services include applications such as Microsoft Internet Information Services (IIS), Index Server, and the Telnet service. You can see and control a complete list of services via the Services Management Console (MMC) snap-in; you can load this add-in by clicking on the Services icon under the Administrative Tools section of the Control Panel (as shown in Figure 7-1).

Figure 7-1. The Services Management Console.

graphics/f07pn01.jpg

Because services run as background processes, they do not require a user to log into the operating system in order to run. Typical applications are launched by users logged into the computer, and they run under the credentials of that user's account. A service is launched by the Service Control Manager (SCM). Figure 7-2 shows the basic life cycle for a service based on the commands sent from the SCM.

Figure 7-2. The life cycle of a Windows service.

graphics/f07pn02.jpg

Individual services are configured to run under specific user accounts ”either a domain user's account or a local machine account (a local user or one of the many predefined system accounts: LocalSystem, LocalService, or NetworkService). Table 7-1 describes the account options for a service.

Table 7-1. Accounts That Services Can Run Under

Account

Account Capabilities

User Specific

Runs with the credentials of a local or network domain user account.

LocalSystem

An account with extensive privileges on the local computer. It can interact with the desktop but has limited access to the network because it has null credentials.

LocalService

Has minimum privileges on the local computer. Uses anonymous credentials for network requests .

NetworkService

Has minimum privileges on the local computer. Can access network resources to allow access to the Everyone or Authenticated Users groups.

Services are, by definition, background processes, but they can contain user interface elements (with design limitations). If a service needs to interact with the desktop, it must run under the LocalSystem account and be set to allow the service to interact with the desktop. (This is done by selecting a check box on the Logon tab of the Properties dialog for the service, as shown in Figure  7-3.) If the service is not set to interact with the desktop, any dialog boxes or message boxes on the main thread will simply cause the service to block because they will not be visible to anyone . The only option is to kill the service process because the SCM will be unable to communicate with the service. A service should not contain any user interface elements (Windows Forms, expected or unexpected dialog boxes, system tray icons, and so forth). If you need an interface with your service, we recommend giving strong consideration about whether the service should be a Windows service or simply a Windows-based application.

Figure 7-3. Service properties dialog box.

graphics/f07pn03.jpg

If a service lacks a user interface, it is common and recommended for the service to register and log events to the Windows Event Log. We would not recommend treating the Event Log as a general-purpose log file ”primarily for performance reasons ”however, logging the starting, stopping, and other various diagnostic- related events of services is the standard approach. The Event Log will be discussed in further detail later in this chapter.

As mentioned earlier, using the Services Management Console is the most common method for controlling a Windows service. The following section contains a discussion on the .NET Framework class which contains properties and methods for programmatically manipulating Windows services.

I l @ ve RuBoard


Designing Enterprise Applications with Microsoft Visual Basic .NET
Designing Enterprise Applications with Microsoft Visual Basic .NET (Pro-Developer)
ISBN: 073561721X
EAN: 2147483647
Year: 2002
Pages: 103

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net