Click here to Skip to main content
13,299,495 members (71,425 online)
Click here to Skip to main content
Add your own
alternative version


16 bookmarked
Posted 17 Apr 2008

Window Services

Rate this:
Please Sign up or sign in to vote.
How to create windows service


This article will help you to create the simple window service which can be useful wile developing a windows application

Using the code

1) open new project select project type as C# --> WindowService templates ( in our case) you can choose VB as per your language preferance

2) This will add default service1.cs file with OnStart and OnStop()

3) choose the designer mode and give appropriate name for your service in property without any space and service name property as display name which can have spaces

4) add the new class (in our case MyWinServiceInstaller.cs) which will be installer class for the service

5) add the .net component reference of System.Configuration.Install Copy paste the code of MyWinServiceInstaller.cs file into your installer class
NB: you can add the displayname, servicename, starttype etc
you can also add userid and password using service process ( inour case its null)

public class MyWinServiceInstaller : System.Configuration.Install.Installer
    public MyWinServiceInstaller()
        ServiceInstaller si = new ServiceInstaller();
        ServiceProcessInstaller spi = new ServiceProcessInstaller();
        si.ServiceName = "MyWinService";
        si.DisplayName = "My Windows Service";
        si.StartType = ServiceStartMode.Automatic;
        spi.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
        spi.Username = null;
        spi.Password = null;


Your service is now ready to run
1)build your solution
2)locate the exe file of your service
3)go to command prompt and locate the following installutil.exe in

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 (for .net framework 2.0)
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322 (for .net framework 1.1)
C:\WINDOWS\Microsoft.NET\Framework\v1.0.3707 (for .net framework 1.0)

or you can use following command

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe c:\samplewinservice\samplewinservice\bin\Release\samplewinservice.exe
for installation 


C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe c:\samplewinservice\samplewinservice\bin\Release\samplewinservice.exe -u
for uninstallation.

you can then go to service management console to view the service installed you have to start the service manually even if it is set as automatic
but it will get start automatically on system start up....

you can verify current sample service working by checking the event log after the service is started

Enjoy servicing........

A trick or tips.

can be use to keep watch on perticular folder and can be used for keepting track of various activity going on records


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

TangoCharli (Anant Tiwari)
Software Developer (Senior) Avenues Technologies Pvt Ltd
India India
MCTS Microsoft Certified Technology Specialist
Computer Engineer

You may also be interested in...


Comments and Discussions

Generalgood article Pin
Donsw17-Jan-09 18:42
memberDonsw17-Jan-09 18:42 
GeneralQuick Overview Pin
Bruce Ricker19-May-08 2:27
memberBruce Ricker19-May-08 2:27 
GeneralNothing New Here Pin
John Simmons / outlaw programmer17-Apr-08 7:12
mvpJohn Simmons / outlaw programmer17-Apr-08 7:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171207.1 | Last Updated 17 Apr 2008
Article Copyright 2008 by TangoCharli (Anant Tiwari)
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid