SlideShare a Scribd company logo
1 of 12
Download to read offline
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

What's hot (9)

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

Similar to How to create C# Windows Service Application

PT1420 File Access and Visual Basic .docx
PT1420 File Access and Visual Basic                      .docxPT1420 File Access and Visual Basic                      .docx
PT1420 File Access and Visual Basic .docx
amrit47
 
Getting started-with-oracle-so a-iv
Getting started-with-oracle-so a-ivGetting started-with-oracle-so a-iv
Getting started-with-oracle-so a-iv
Amit Sharma
 
Autoresponders... Your Web Site Automator, Organizer And Time Saver
Autoresponders... Your Web Site Automator, Organizer And Time SaverAutoresponders... Your Web Site Automator, Organizer And Time Saver
Autoresponders... Your Web Site Automator, Organizer And Time Saver
watch9minute
 
Create yourfirstandroidapppdf
Create yourfirstandroidapppdfCreate yourfirstandroidapppdf
Create yourfirstandroidapppdf
murad3003
 
Oracle apex hands on lab#2
Oracle apex hands on lab#2Oracle apex hands on lab#2
Oracle apex hands on lab#2
Amit Sharma
 
WASPNEWServerDecoumentation
WASPNEWServerDecoumentationWASPNEWServerDecoumentation
WASPNEWServerDecoumentation
James Willis
 

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

Web services in asp.net
Web services in asp.netWeb services in asp.net
Web services in asp.net
 
Details Description of Load Runner Recording option
Details Description of  Load Runner Recording optionDetails Description of  Load Runner Recording option
Details Description of Load Runner Recording option
 
Vb.net ide
Vb.net ideVb.net ide
Vb.net ide
 
Visual studio 2012
Visual studio 2012Visual studio 2012
Visual studio 2012
 
PT1420 File Access and Visual Basic .docx
PT1420 File Access and Visual Basic                      .docxPT1420 File Access and Visual Basic                      .docx
PT1420 File Access and Visual Basic .docx
 
Getting started-with-oracle-so a-iv
Getting started-with-oracle-so a-ivGetting started-with-oracle-so a-iv
Getting started-with-oracle-so a-iv
 
Firebase crashlytics integration in iOS swift (dSYM File Required Problem Res...
Firebase crashlytics integration in iOS swift (dSYM File Required Problem Res...Firebase crashlytics integration in iOS swift (dSYM File Required Problem Res...
Firebase crashlytics integration in iOS swift (dSYM File Required Problem Res...
 
Containers Lab
Containers Lab Containers Lab
Containers Lab
 
Jsp myeclipse
Jsp myeclipseJsp myeclipse
Jsp myeclipse
 
Java Servlets Part 2
Java Servlets Part 2Java Servlets Part 2
Java Servlets Part 2
 
Building A Simple Web Service With CXF
Building A Simple Web Service With CXFBuilding A Simple Web Service With CXF
Building A Simple Web Service With CXF
 
CI & CD- mobile application
CI & CD- mobile applicationCI & CD- mobile application
CI & CD- mobile application
 
CI & CD- mobile application
CI & CD- mobile applicationCI & CD- mobile application
CI & CD- mobile application
 
Autoresponders... Your Web Site Automator, Organizer And Time Saver
Autoresponders... Your Web Site Automator, Organizer And Time SaverAutoresponders... Your Web Site Automator, Organizer And Time Saver
Autoresponders... Your Web Site Automator, Organizer And Time Saver
 
Create yourfirstandroidapppdf
Create yourfirstandroidapppdfCreate yourfirstandroidapppdf
Create yourfirstandroidapppdf
 
Mca 504 dotnet_unit5
Mca 504 dotnet_unit5Mca 504 dotnet_unit5
Mca 504 dotnet_unit5
 
Oracle apex hands on lab#2
Oracle apex hands on lab#2Oracle apex hands on lab#2
Oracle apex hands on lab#2
 
DotNetNuke
DotNetNukeDotNetNuke
DotNetNuke
 
WASPNEWServerDecoumentation
WASPNEWServerDecoumentationWASPNEWServerDecoumentation
WASPNEWServerDecoumentation
 
Visual c++ 2010_tutorial
Visual c++ 2010_tutorialVisual c++ 2010_tutorial
Visual c++ 2010_tutorial
 

Recently uploaded

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 

Recently uploaded (20)

WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 

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. ================================ (~_~)(~_~)(~_~)================================