How to create a simple Windows Service in C# and Install it using Installutil

Created: 05/02/2013 10:33:18 p.m.

How to create a simple Windows Service in C#  and Install it using Installutil

I will explain just a simple method to deploy your own windows service.

1) First we will create a Windows Service project.

2) Make sure you have the similar basic structure like this.

3) Now very important, we need to add installer controll to our project, for this we will create our custom installer like this: Add simpe c# class and call it like "MyWindowsServiceInstaller.cs"

4) Now to use all the required classes in our project we need to add one reference for "System.Configuration.Install" library and appropriate references in our class.

5) Now we need to add some code to our installer to make it installer it self. Just do it like this:

I puth here the Constructor code:

public MyWindowsServiceInstaller()
            ServiceProcessInstaller serviceProcessInstaller =
                              new ServiceProcessInstaller();
            ServiceInstaller serviceInstaller = new ServiceInstaller();

            //# Service Account Information
            serviceProcessInstaller.Account = ServiceAccount.LocalSystem;
            serviceProcessInstaller.Username = null;
            serviceProcessInstaller.Password = null;

            //# Service Information
            serviceInstaller.DisplayName = "My New C# Windows Service";
            serviceInstaller.StartType = ServiceStartMode.Automatic;

            //# This must be identical to the WindowsService.ServiceBase name
            //# set in the constructor of WindowsService.cs
            serviceInstaller.ServiceName = "My Windows Service";



6) Now build your service application and go to Debug folder to see your app.exe

7) Thats all now we will install this service using InstallUtil and CMD

Got to run and open CMD AS ADMINISTRATOR!!

Make sure that you have this file: C:\Windows\Microsoft.NET\Framework\v2.0.50727\

Write in CMD: "cd\" then press Enter

Copy your InstallUtil url and past it on CMD like this:

cd C:\Windows\Microsoft.NET\Framework\v2.0.50727\ and press enter

And now we need to install our Service that is located in our Debug folder using InstallUtil.
So just type the follow line: InstallUtil /i "C:\Users\Mak\Documents\Visual Studio 2008\Projects\ MyServiceApp\MyServiceApp\bin\Debug\MyServiceApp.exe"

You will obtain the following window:

That meen that your service was installed and you can find it here:

To uninstall this service just use "/u" instead of "/i" like:

InstallUtil /u "C:\Users\Mak\Documents\Visual Studio 2008\Projects\MyServiceApp\ MyServiceApp\bin\Debug\MyServiceApp.exe"


Hope this helps somebody!
If you found any incoherence in this article, just denunce it
above this site!

To create the installer class i used code that i found in google, you can modify it to get the proper results.

Thank you for your visit!


User: Test Comment date: 06/12/2013 05:31:16 a.m.
Test for mail..
User: jigar patel Comment date: 09/01/2014 08:27:23 a.m.
User: Betty Comment date: 15/01/2014 09:22:28 a.m.
Very useful! Thanks...
User: hari Comment date: 31/01/2014 03:10:06 a.m.
Thanks. Useful & simple method
User: Paul Comment date: 03/03/2014 06:49:07 p.m.
Very clear. Thank you!
User: Tyson Comment date: 04/03/2014 02:33:12 p.m.
Simple, exactly what I needed!
User: Mohit Diwakar Comment date: 06/03/2014 10:20:59 a.m.
Good Article, Well descrption
User: pavithra Comment date: 06/03/2014 01:10:41 p.m.
thanks.detailed explanation.
User: Usman Comment date: 07/03/2014 09:05:44 a.m.
its not working.
what i should do in this step which i mention below.
  serviceInstaller.ServiceName = "My Windows Service";
i place the name of my service, but it gives me an error.

User: Maksym Comment date: 08/03/2014 10:29:40 a.m.
Hello usman, What error it gives you?
User: Masnij Comment date: 18/03/2014 07:29:40 a.m.
mast re mitra

User: Shiv Comment date: 17/06/2014 09:03:06 a.m.
very nice
User: ddd Comment date: 18/06/2014 06:34:36 a.m.
User: Foog Comment date: 26/06/2014 11:29:52 p.m.
Fanbobbledoo article boogerooman!
User: Joaquin Comment date: 03/07/2014 03:37:23 p.m.
Muy bueno, muy útil :D
User: Joaquin Comment date: 10/09/2014 01:03:21 p.m.
User: Loai Comment date: 18/02/2015 08:41:29 a.m.
Thank U a lot. 

Go to Comments