Click here to Skip to main content
15,896,269 members
Articles / Mobile Apps

Simple Windows Service Sample

Rate me:
Please Sign up or sign in to vote.
4.85/5 (407 votes)
14 Jul 20037 min read 3M   69.3K   836  
A simple application to show how to create a Windows service.
using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration.Install;

namespace MyNewService
{
	/// <summary>
	/// Summary description for ProjectInstaller.
	/// </summary>
	[RunInstaller(true)]
	public class ProjectInstaller : System.Configuration.Install.Installer
	{
		private System.ServiceProcess.ServiceProcessInstaller serviceProcessInstaller1;
		private System.ServiceProcess.ServiceInstaller serviceInstaller1;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public ProjectInstaller()
		{
			// This call is required by the Designer.
			InitializeComponent();

			// TODO: Add any initialization after the InitComponent call
		}

		#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.serviceProcessInstaller1 = new System.ServiceProcess.ServiceProcessInstaller();
			this.serviceInstaller1 = new System.ServiceProcess.ServiceInstaller();
			// 
			// serviceProcessInstaller1
			// 
			this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
			this.serviceProcessInstaller1.Password = null;
			this.serviceProcessInstaller1.Username = null;
			// 
			// serviceInstaller1
			// 
			this.serviceInstaller1.ServiceName = "MyNewService";
			this.serviceInstaller1.StartType = System.ServiceProcess.ServiceStartMode.Automatic;
			// 
			// ProjectInstaller
			// 
			this.Installers.AddRange(new System.Configuration.Install.Installer[] {
																					  this.serviceProcessInstaller1,
																					  this.serviceInstaller1});

		}
		#endregion
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Saudi Arabia Saudi Arabia
i've been with .net for about 5 years since the beta 1.0 ver. along with ASP.net and windows services..
am experienced in Java, C, C++, Prolog, Assembly, ASP, VB, VB.net, C# and ASP.net

am very fond of Web Development and Graphics Libraries Programming like Open GL,CSGL and SDGL

worked in Microsoft Egypt Co., Delta Software and now am working in Al-Alamiah Sakhr Co., Riyadh, saudi arabia.

+966-508969725

Comments and Discussions