Tuesday, October 27, 2009

Service Controllers and System.ServiceProcess namespace

From the Skills being Measured:

"Implement, install, and control a service."

These are Windows Services (the same services that we all know and love under the Control Panel -> Administration Tools -> Services).

The relevant classes, structs, enums are in the following namespace:

System.ServiceProcess

Here are some of the key classes:

  • ServiceBase - base class that should be extended by any new class that will run as a Windows Service. Implementing a service involves extending ServiceBase and providing behavior that will occur when the service is started, stopped, paused, continued. All services that extend ServiceBase should implement OnStart and OnStop, and may also implement OnPause and OnContinue.
  • ServiceController - represents an existing Windows Service, allows for the service to be stopped, started, manipulated, and information to be obtained about it. Here is an excellent example of a ServiceController on CodeProject. GetServices is a static method that will return an array of ServiceController objects.
  • ServiceControllerPermission - From MSDN: Allows control of code access security permissions for service controllers. I could not find any samples on how to use ServiceControllerPermission class, nor could I find any properties or methods in ServiceController that demonstrated how to use the ServiceControllerPermission.
  • ServiceInstaller - Installs a Service class (class that extends System.ServiceProcess.ServiceBase). Should be called by installation utility. The method ServiceInstaller.Install will be automatically called by the install utility, and if anything goes wrong, ServiceInstaller.Rollback will be called.
  • ServiceProcessInstaller - Installs a Service class. Can be used to specify that the Service will run under a different account (such as the Local System account).
  • SessionChangeDescription (struct) - Contains reason for Terminal Services session change. Has a property, Reason, which is an enum of SessionChangeReason.
  • SessionChangeReason (enum) - See SessionChangeDescription.Reason property.

No comments:

Post a Comment