Create Windows Services in the .Net Framework
By Douglas Reilly, May 01, 2002
One of the unsung heroes in the success of Microsoft 2000 is the ability to run applications as services, and now, as Douglas shows us, the .Net Framework makes creating a Windows Service much easier.
Create Windows Services in the .Net Framework
Example 2:
The ProjectInstaller.cs class
using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration.Install;
namespace SqlMonitorService
{
/// <summary>
/// Summary description for ProjectInstaller.
/// </summary>
[RunInstaller(true)]
public class ProjectInstaller :
System.Configuration.Install.Installer
{
private System.ServiceProcess.ServiceProcessInstaller
SqlMonitorServiceProcessInstaller;
private System.ServiceProcess.ServiceInstaller
SqlMonitorServiceInstaller;
/// <summary>
/// Required designer variable.
/// </summary>
// private System.ComponentModel.Container
// components = null;
public ProjectInstaller()
{
// This call is required by the Designer.
InitializeComponent();
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.SqlMonitorServiceProcessInstaller =
new
System.ServiceProcess.ServiceProcessInstaller(
);
this.SqlMonitorServiceInstaller =
new System.ServiceProcess.ServiceInstaller();
//
// SqlMonitorServiceProcessInstaller
//
this.SqlMonitorServiceProcessInstaller.Account =
System.ServiceProcess.ServiceAccount.LocalSystem;
this.SqlMonitorServiceProcessInstaller.Password = null;
this.SqlMonitorServiceProcessInstaller.Username = null;
//
// SqlMonitorServiceInstaller
//
this.SqlMonitorServiceInstaller.ServiceName =
"SQLMonitorService";
this.SqlMonitorServiceInstaller.StartType =
System.ServiceProcess.ServiceStartMode.Automatic;
//
// ProjectInstaller
//
this.Installers.AddRange(
new System.Configuration.Install.Installer[] {
this.SqlMonitorServiceProcessInstaller,
this.SqlMonitorServiceInstaller});
}
#endregion
}
}