Jul 1, 2012

Create Windows Service in .Net

Leave a Comment
This example explains step-by-step how to create a windows service in .Net using Visual Studio.
Create new project and select windows service (Visual C# / Windows / Windows Service). Enter the project name as you like, e.g. "MyService".

View designer of the Service1.cs and Click on design surface then, you will see properties window on right side as shown in below image. Click Add Installer in the Properties window.

It adds a ProjectInstaller­.cs file to the project. This file contains two components, a ServiceInsta­ller and a ServiceProces­sInstaller.
Click to serviceInstaller1 and in the Properties window set ServiceName to "MyService", change DisplayName (shown in Microsoft Management Console) and fill in the Description field. You can also set StartType to automatic or manual service starting as per your need.

 Click to serviceProces­sInstaller1 and change the Account property to a value you need. It's an account under which the system runs the service. Account descriptions can be found in ServiceAccount enumeration

Complete the implementation of OnStart and OnStop methods in the service class.

 That all now we got a service. In the next article we will learn how to install/uninstall the service.


Post a Comment