How To Create a Window Service in

Want to learn how to create a window service in C#? Vizteck is giving you a step-by-step detailed guide for it.




May 1, 2015





Window Service creates executable applications that run in its Window Session. Depending upon the configuration setting, they can start manually or automatically when the computer starts. I’ll explain step by step how to create a Window Service in C#.Net.

  • Click File -> New Project.
  • Select Window Service Template.
  • Name the service MyWindowService.
  • Rename the Service1.cs to MyService.cs.
  • Add Event log to the Service, by clicking tool and dropingEventLog.
  • Rename the eventLog1 to EventLog4MyService.'




  • Right, Click the MyService.cs and select View designer.
  • In the designer window right click and click Add “Add Installer”.
  • Select serviceProcessInstaller1 and in the property window, adjust the fields as in the below figure.



  • Right-click MyService and select code. Type the following code.


html 10.PNG

html 9.PNG

How To Build and Deploy the Service


  • Right Click the MyWindowService project and select properties.
  • Select the Target Framework. (in my case it is 4.5)

html 8.PNG


  • Select targetplateform (in my case x64).


  • Type PostBuild Events Commands



  • This command will uninstall


  • This command will install MyWindowService.exe.


  • Now Build the project. If the build is successful, the service will also be installed.

html 3.PNG


Create a file in the notepad, and type the following script

html2.PNGSave the file as “install.bat”.To uninstall the service, use the following script in another Uninstall.bat file.



Running the file as administrator will install the service. Type services. MSC and go to services and run the service.



(Window Service “MyService” has successfully installed)


Islamabad, Pakistan

Floor 2, Building 145, Civic Center Bahria Town Phase 4, Islamabad, Pakistan


1 squire armor road, windham, NH,03076

Saudi Arabia

7654 Prince Nawaf Street, Al Khobar, 34426

Kingdom Of Bahrain

No 851, Bldg No 2420, Rd No 2831, Seef District, Block 428