Windows Services
By: Vinay Hatwal
Dated: Apr 10, 2009
Level: Beginner
The idea of using Windows services came into my mind when I was working on Finger Print Attendance System for Bajaj Capital Ltd. This system was going to be used by all the branches of the company. So I wanted to synchronize the attendance of the employees of each branch with our company’s ERP system. So that, I decided to develop windows services for the same purpose. There was one issue in real time synchronization of attendance with the Head Office. The issue was slow internet connection and no internet connectivity available all the time. So the solution was to send the attendance when internet is connected not on the time of attendance punching. So the solution was WINDOWS SERVICES.
In this article I will explain how to make Windows Services by using c#.net.
Windows services are long running executable file developed for running in background as long a windows is running. These executables run in the background and there is no any requirement for the user interaction. They run in the background so that there is no need to take graphical interface in the Windows Services. You can think about UNIX Daemon if u r familiar with the UNIX environment. On the Windows the same concept is Windows Services. Windows Services can be configured to run automatically when Windows is booted. They can also be configured to run on Local machine, single user account, and also on Network.
You can find windows services in your local machine on
Start-> Control Panel -> Administrative Tools -> Services
These services looks like this—

Windows Service Browser
By using windows service you can use databases, text files, and all shareable resources with it etc.
To create Windows Services in .net (I am creating in .net 2.0)
Creating Windows Services
<!–[if !supportLists]–>1) <!–[endif]–>To create windows services, go to File menu and then select New Project, then select Windows Service. You will see the dialog box shown below. Name the project – MyWindowService.

2) After clicking on OK you will see the following. Change the name of the service from Service1.cs to MyService.cs.

3) Now go to in on the properties on the MyService and change the property Service Name to MyService.
4) Do right click on the MyService design view and select View Code option from the context menu. You can see two overrided methods in the window OnStart() and OnStop().
These are the members of the ServiceBase class and inheritted by the MyService Class. There are some more members also present in the ServiceBase class like OnContinue(), OnPause() etc. but I am just describing about these two only.
The idea of using windows service is only behind these to methods. Any work u want to perform on the sharable resources, you can write code for that in the OnStart() method. I have just put Beep () here. It will give the beep sound on starting the Window Service. And just 2 beep on Stoping it. You can see in the coding below.

<!–[if !supportLists]–>5) <!–[endif]–>to install this Windows Service on the local system you need to add installers in your Service. Just right click on the Service Design window and then select Add Installer.
<!–[if !supportLists]–>6) <!–[endif]–>Project Installer will automatically be added in your solution, name ProjectInstaller.sc. and you can also find two component in it
<!–[if !supportLists]–>a. <!–[endif]–>serviceProcessInstaller1
<!–[if !supportLists]–>b. <!–[endif]–>serviceInstaller1
<!–[if !supportLists]–>7) <!–[endif]–>You can now decide how your Windows Process will be display, you can set the account for your service on which it will be running, and you can give the Display Service Name, Description and the start type of the service like Automat, Manual, or Disabled. For doing all these you can follow these steps
<!–[if !supportLists]–>a. <!–[endif]–>Go to on the properties of serviceProcessInstaller1, and set Account property to Local System, so that it would be sharable to all users.
<!–[if !supportLists]–>b. <!–[endif]–>Now go to on the properties of serviceInstaller1, and ser Description as u like and set Display Name as u want to display in the Services Console, and now set StartType to Automatic so that the service can be run on the starting of the Windows operation system.
<!–[if !supportLists]–>
<!–[endif]–>After doing all the configuration just press F6 for building the solution. Now Your Window Service is ready to use.
<!–[if !supportLists]–>9) <!–[endif]–>Now for using it u have to install this service on your local machine. You can do this by using the instalUtill.exe utility provided by .net framework to install this service on your machine.
Now take the executable of this service and jus copy it into your system32 directory.
Go to your application path where your project is running, and go to the bin\debug directory then copy MyWindowServices.exe and paste it into syetem32.
Now go to on the Visual Studio 2005 Command Prompt and type the following for installing the newly developed Window Service–
C:\> installutil c:\windows\system32\ MyWindowServices.exe

To uninstall use –
C:\> installutil /u c:\windows\system32\ MyWindowServices.exe
You can see your service in the service console like

Now just do right click on it and the start. You will listen one beep on starting and two beep on stopping the Windows Service.
So friends. Enjoy the Window Services, hope your will learn by this article. Hope you will be enjoying after creation the windows service.
I am always waiting for your comments and suggestion so that I can improve my articles.
Again Coming Soon…………………….
Vinay Hatwal