SlideShare a Scribd company logo
3
Most read
4
Most read
6
Most read
Create windows service application
(Step By Step)
In this tutorial we’ll create a windows service application. Suppose we’ve service which gives us
notification in a text file when it starts and stop. Let’s create the service.
1. Create a project with your visual studio.
Create windows service application
(Step By Step)
2. Now select Windows Service application as shown below.
3. Now add an installer.
Create windows service application
(Step By Step)
4. After selection “Add Installer”, a file named “ProjectInstaller.cs” will be added in your solutions.
And there will be to things like label named “serviceInstaller1” and “serviceProcessInstaller1”.
First select “serviceInstaller1” and go to properties. Then change the marked values as shown in
image.
5. Now right click on “serviceProcessInstaller1” and go to properties then change the values as shown
in image.
Create windows service application
(Step By Step)
6. Now Right click on your project and Create Public static class Named “Library.cs”. Like shown in
image. And paste the following code inside the class.
using System.IO;
public static void WriteErrorLog(Exception ex)
{
StreamWriter sw = null;
try
{
sw = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "LogFile.txt", true);
sw.WriteLine(DateTime.Now.ToString() + ": " + ex.Source.ToString().Trim() + "; " +
ex.Message.ToString().Trim());
sw.Flush();
sw.Close();
}
catch
{
//nothting
}
}
public static void WriteErrorLog(string Message)
{
StreamWriter sw = null;
try
{
sw = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "LogFile.txt", true);
sw.WriteLine(DateTime.Now.ToString() + ": " + Message);
sw.Flush();
sw.Close();
}
catch
{
//nothing
}
}
Create windows service application
(Step By Step)
7. Now Right Click on your project > then select “Open Folder in File Explorer” > bin> Debug> Create a
text file named “LogFile.txt”.
8. Now Expand your Service (Ex. Here is Service1.cs) and double click on Service1.cs and write the
code showed in image.
Create windows service application
(Step By Step)
9. Now Save all changes and build your application. And Run Visual Studio Command Prompt as
Administrator mode. Change the directory to application’s drive as showed the following image (Ex.:
here our directory is “G”) and hit enter key.
10. Now Right Click on your project > then select “Open Folder in File Explorer” > bin> Debug> and
copy the directory from address bar. And then type cd <space> then paste the directory you copied
and hit enter key. As like the following image.
Create windows service application
(Step By Step)
11. Right Click on your project > then select “Open Folder in File Explorer” > bin> Debug>
Then copy your service name (Ex. Here our service name is “MyFirstServiceApp.exe”).
Now type “installutil.exe” <space> paste your service name you copied (in this case our service
name is “MyFirstServiceApp.exe”) from Debug folder in your project as same as showed in
following picture And hit enter key.
Create windows service application
(Step By Step)
12. If everything are ok then you will get this type of result in your cmd and it means your service is
ready to work.
Create windows service application
(Step By Step)
13. Now navigate to windows services from start menu and run is as administrator.
Create windows service application
(Step By Step)
14. Now follow the find your services (i.e.: Here our service Name is “MyFirstService” ) and click on
it then click on Start from left side of the service window.
Create windows service application
(Step By Step)
15. Right Click on your project > then select “Open Folder in File Explorer” > bin> Debug> and open the
text file Name “LogFile.txt”. You will see the following text has written in your text file. That means
your service is working as your expectation. Close the text file.
Create windows service application
(Step By Step)
16. Now once again go to service as described in 13 step. And stop your service as shown in picture
bellow.
17. Open your text file named “LogFile.txt” as described in step 15. Now you will see another line has
added in your text file which tells your service has stopped as same as following picture.
================================ (~_~)(~_~)(~_~)================================

More Related Content

PDF
Windows Phone Workshop: WCF services
DOCX
Installing Process Oracle 10g Database Software on Windows 10
PDF
Windows Communication Foundation (WCF) programming using Visual Studio
PPT
Maintenance Reporting Website
PDF
Admin Habits & Hacks Handout - Salesforce World Tour Boston
PPTX
Servlet session 3
PPTX
exe in MatLab
PDF
Getting started-with-oracle-so a-iv
Windows Phone Workshop: WCF services
Installing Process Oracle 10g Database Software on Windows 10
Windows Communication Foundation (WCF) programming using Visual Studio
Maintenance Reporting Website
Admin Habits & Hacks Handout - Salesforce World Tour Boston
Servlet session 3
exe in MatLab
Getting started-with-oracle-so a-iv

What's hot (9)

PPTX
Microsoft office access 2003
PPTX
ChangesChecklist
 
PPTX
Offline blog tools
PDF
SoapUI: Day9 : Web service : Service mocking
PPTX
Ecse ts student instructional guide
 
PPTX
Github plugin setup in anypointstudio
PDF
Getting started-with-oracle-so a- lab 11
PPTX
Deployment options for mule applications
PPTX
Web mail vs Desktop
Microsoft office access 2003
ChangesChecklist
 
Offline blog tools
SoapUI: Day9 : Web service : Service mocking
Ecse ts student instructional guide
 
Github plugin setup in anypointstudio
Getting started-with-oracle-so a- lab 11
Deployment options for mule applications
Web mail vs Desktop
Ad

Similar to How to create C# Windows Service Application (20)

PPTX
45c
PPT
Introduction To Windows Services
PPTX
IIS Always-On Services
PPTX
Fun with windows services
PPT
PDC Highlights
PPTX
Topic # 12 of outline Configuring Local Services.pptx
PDF
Delphi - Howto Services
PPTX
Windows service best practice
PPTX
Windows Services 101
PDF
Tutorial windows service with java (procrun)
PPT
Msdn Workflow Services And Windows Server App Fabric
PDF
DotNet Cologne 2015 - Windows 10 AppDev, Teil2: Coole APIs - (Daniel Meixner)
PDF
Work flow api reference
PPTX
Windows 8 BootCamp
PPT
Windows Workflow Foundation
PDF
WCF Multi Layer Services Development with Entity Framework 4th Edition Editio...
PPT
Session 2
PPTX
Services I.pptx
 
PDF
Introduction to the SQL and Windows Azure Platform
45c
Introduction To Windows Services
IIS Always-On Services
Fun with windows services
PDC Highlights
Topic # 12 of outline Configuring Local Services.pptx
Delphi - Howto Services
Windows service best practice
Windows Services 101
Tutorial windows service with java (procrun)
Msdn Workflow Services And Windows Server App Fabric
DotNet Cologne 2015 - Windows 10 AppDev, Teil2: Coole APIs - (Daniel Meixner)
Work flow api reference
Windows 8 BootCamp
Windows Workflow Foundation
WCF Multi Layer Services Development with Entity Framework 4th Edition Editio...
Session 2
Services I.pptx
 
Introduction to the SQL and Windows Azure Platform
Ad

Recently uploaded (20)

PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Digital Systems & Binary Numbers (comprehensive )
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
assetexplorer- product-overview - presentation
PDF
Designing Intelligence for the Shop Floor.pdf
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
history of c programming in notes for students .pptx
PPTX
Computer Software and OS of computer science of grade 11.pptx
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPT
Introduction Database Management System for Course Database
PDF
System and Network Administration Chapter 2
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
 
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
top salesforce developer skills in 2025.pdf
PDF
Odoo Companies in India – Driving Business Transformation.pdf
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PTS Company Brochure 2025 (1).pdf.......
Digital Systems & Binary Numbers (comprehensive )
Wondershare Filmora 15 Crack With Activation Key [2025
assetexplorer- product-overview - presentation
Designing Intelligence for the Shop Floor.pdf
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
history of c programming in notes for students .pptx
Computer Software and OS of computer science of grade 11.pptx
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Introduction Database Management System for Course Database
System and Network Administration Chapter 2
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
How to Migrate SBCGlobal Email to Yahoo Easily
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
 
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Operating system designcfffgfgggggggvggggggggg
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
top salesforce developer skills in 2025.pdf
Odoo Companies in India – Driving Business Transformation.pdf

How to create C# Windows Service Application

  • 1. Create windows service application (Step By Step) In this tutorial we’ll create a windows service application. Suppose we’ve service which gives us notification in a text file when it starts and stop. Let’s create the service. 1. Create a project with your visual studio.
  • 2. Create windows service application (Step By Step) 2. Now select Windows Service application as shown below. 3. Now add an installer.
  • 3. Create windows service application (Step By Step) 4. After selection “Add Installer”, a file named “ProjectInstaller.cs” will be added in your solutions. And there will be to things like label named “serviceInstaller1” and “serviceProcessInstaller1”. First select “serviceInstaller1” and go to properties. Then change the marked values as shown in image. 5. Now right click on “serviceProcessInstaller1” and go to properties then change the values as shown in image.
  • 4. Create windows service application (Step By Step) 6. Now Right click on your project and Create Public static class Named “Library.cs”. Like shown in image. And paste the following code inside the class. using System.IO; public static void WriteErrorLog(Exception ex) { StreamWriter sw = null; try { sw = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "LogFile.txt", true); sw.WriteLine(DateTime.Now.ToString() + ": " + ex.Source.ToString().Trim() + "; " + ex.Message.ToString().Trim()); sw.Flush(); sw.Close(); } catch { //nothting } } public static void WriteErrorLog(string Message) { StreamWriter sw = null; try { sw = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "LogFile.txt", true); sw.WriteLine(DateTime.Now.ToString() + ": " + Message); sw.Flush(); sw.Close(); } catch { //nothing } }
  • 5. Create windows service application (Step By Step) 7. Now Right Click on your project > then select “Open Folder in File Explorer” > bin> Debug> Create a text file named “LogFile.txt”. 8. Now Expand your Service (Ex. Here is Service1.cs) and double click on Service1.cs and write the code showed in image.
  • 6. Create windows service application (Step By Step) 9. Now Save all changes and build your application. And Run Visual Studio Command Prompt as Administrator mode. Change the directory to application’s drive as showed the following image (Ex.: here our directory is “G”) and hit enter key. 10. Now Right Click on your project > then select “Open Folder in File Explorer” > bin> Debug> and copy the directory from address bar. And then type cd <space> then paste the directory you copied and hit enter key. As like the following image.
  • 7. Create windows service application (Step By Step) 11. Right Click on your project > then select “Open Folder in File Explorer” > bin> Debug> Then copy your service name (Ex. Here our service name is “MyFirstServiceApp.exe”). Now type “installutil.exe” <space> paste your service name you copied (in this case our service name is “MyFirstServiceApp.exe”) from Debug folder in your project as same as showed in following picture And hit enter key.
  • 8. Create windows service application (Step By Step) 12. If everything are ok then you will get this type of result in your cmd and it means your service is ready to work.
  • 9. Create windows service application (Step By Step) 13. Now navigate to windows services from start menu and run is as administrator.
  • 10. Create windows service application (Step By Step) 14. Now follow the find your services (i.e.: Here our service Name is “MyFirstService” ) and click on it then click on Start from left side of the service window.
  • 11. Create windows service application (Step By Step) 15. Right Click on your project > then select “Open Folder in File Explorer” > bin> Debug> and open the text file Name “LogFile.txt”. You will see the following text has written in your text file. That means your service is working as your expectation. Close the text file.
  • 12. Create windows service application (Step By Step) 16. Now once again go to service as described in 13 step. And stop your service as shown in picture bellow. 17. Open your text file named “LogFile.txt” as described in step 15. Now you will see another line has added in your text file which tells your service has stopped as same as following picture. ================================ (~_~)(~_~)(~_~)================================