Send suggestion to this article/site (New)
Send suggestion

Autor: Maksym.P
Created: 05/02/2013 10:33:18 p.m.
Article valuation: Very helpful
Votes count: 33

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\InstallUtil.exe

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!


[ 0 ]Name: Test    Mail:

Test for mail..

Created date: 06/12/2013 05:31:16 a.m.
[ 1 ]Name: jigar patel    Mail:


Created date: 09/01/2014 08:27:23 a.m.
[ 2 ]Name: Betty    Mail:

Very useful! Thanks...

Created date: 15/01/2014 09:22:28 a.m.
[ 3 ]Name: hari    Mail:

Thanks. Useful & simple method

Created date: 31/01/2014 03:10:06 a.m.
[ 4 ]Name: Paul    Mail:

Very clear. Thank you!

Created date: 03/03/2014 06:49:07 p.m.
[ 5 ]Name: Tyson    Mail:

Simple, exactly what I needed!

Created date: 04/03/2014 02:33:12 p.m.
[ 6 ]Name: Mohit Diwakar    Mail:

Good Article, Well descrption

Created date: 06/03/2014 10:20:59 a.m.
[ 7 ]Name: pavithra    Mail:

thanks.detailed explanation.

Created date: 06/03/2014 01:10:41 p.m.
[ 8 ]Name: Usman    Mail: usman@gmail.cmo

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.

Created date: 07/03/2014 09:05:44 a.m.
[ 9 ]Name: Maksym    Mail:

Hello usman, What error it gives you?

Created date: 08/03/2014 10:29:40 a.m.
[ 10 ]Name: Masnij    Mail:

mast re mitra

Created date: 18/03/2014 07:29:40 a.m.
[ 11 ]Name: Shiv    Mail:

very nice

Created date: 17/06/2014 09:03:06 a.m.
[ 12 ]Name: ddd    Mail: sddf@d.dfd


Created date: 18/06/2014 06:34:36 a.m.
[ 13 ]Name: Foog    Mail:

Fanbobbledoo article boogerooman!

Created date: 26/06/2014 11:29:52 p.m.
[ 14 ]Name: Joaquin    Mail:

Muy bueno, muy útil :D

Created date: 03/07/2014 03:37:23 p.m.

Name:     Email:  
Comment:   © - 2011-2014 | Contact | Subscribe