Windows 2000 Service Features

 
Chapter 22 - Windows Services
bySimon Robinsonet al.
Wrox Press 2002
  

Let's take a look at the features of Windows Services in Windows 2000.

Network Binding Changes and Power Events

With Windows 2000, it's not necessary to reboot the system as often as it was with Windows NT; for example, it's not necessary to reboot the system when the IP address changes. To make this possible, a service receives events when the address changes and can act accordingly .

Windows 2000 sends these control codes to services when the network binding changes:

Control code

Description

SERVICE_CONTROL_NETBINDADD

A new component for binding is available.

SERVICE_CONTROL_NETBINDREMOVE

A component for binding has been removed. It's necessary to re-read the binding information and unbind from the removed component.

SERVICE_CONTROL_NETBINDENABLE

A previously disabled binding is now enabled.

SERVICE_CONTROL_NETBINDDISABLE

A previously enabled binding is now disabled.

If the service is using a binding, it's necessary to re-read the binding information and remove the bindings that are no longer available. Thus the service can react to networking changes so a reboot is not necessary.

Windows 2000 also adds a lot of power management support. There's support to hibernate the system the memory gets written to disk, so a faster boot is possible. It's also possible to suspend the system in order to reduce the power consumption, but it can automatically be awakened when needed.

For all power events, the service can receive the control code SERVICE_CONTROL_POWEREVENT with additional parameters. The reason for the event is passed through these parameters. The reason could be low battery power, or that the system is going to a suspended state, or a power status change. Depending on the reason code the service should slow down, suspend background threads, close network connections, close files, and so on.

The classes in the System.ServiceProcess namespace have support for these Windows 2000 features, too. In the same way as we can configure a service so that it reacts to pause and continue events with the CanPauseAndContinue property, we can also set a property for power management: CanHandlePowerEvent . Windows 2000 services that handle power events are registered in the SCM with the Win32 API method RegisterServiceCtrlHandlerEx() .

With a CanHandlePowerEvent value of true the method:

   protected virtual bool OnPowerEvent(PowerBroadcastStatus powerStatus);   

will be called as soon as the power status changes. Some of the values we get from the PowerBroadcastStatu s enumeration are listed in this table:

Value

Description

BatteryLow

The battery power is low. We should reduce the functionality of the service to a minimum.

PowerStatusChange

A switch from battery power to A/C happened , or the battery power slips below a threshold, and so on.

QuerySuspend

The system requests permissions to go into a suspended mode. We could deny the permissions, or prepare to go into the suspended mode by closing files, disconnecting network connections, and so on.

QuerySuspendFailed

Change into the suspended mode was denied for the system. We can go on with the functionality as before.

Suspend

Nobody denied the request to go into the suspended mode. The system will be suspended soon.

Recovery

Automatic recovery is a feature that's just a configuration issue and can be used for all services running on Windows 2000. If a service process crashes then the service can be automatically restarted, or a special file can be configured to run, or the complete system can be automatically rebooted. There's usually a reason why a service crashes and therefore we don't want to automatically reboot the system continuously; we can differentiate responses to first, second, and subsequent failures.

We can configure the recovery options using the properties in the Computer Management MMC Administrator tool:

click to expand

COM+ Applications as Services

Starting with Windows XP it's possible that a COM+ application (as long as it is configured as a server application) can run as a service. What's the advantage of this? With Windows XP a service can have direct access to COM+ services such as transactions, object pooling, and so on. If we want to use COM+ Services with Windows 2000 in a Windows Service we have to build two separate applications: one application deals with the service functionality, the second with the COM+ services. Let's look at the advantages this brings us:

  • It's easier to create a service application. We no longer have to deal with the service-specific installation as this can be done directly from the COM+ configuration.

  • A COM+ application can act like a service. It can be automatically started at boot time, it can have the rights of the system account, and it can react to service control codes we are sending from a service control program.

  • The service application that's created as a COM+ application can have direct access to the COM+ services such as transaction management, object pooling, and so on.

  


Professional C#. 2nd Edition
Performance Consulting: A Practical Guide for HR and Learning Professionals
ISBN: 1576754359
EAN: 2147483647
Year: 2002
Pages: 244

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