Go to File -- > New -- > Project -- >Visual C# -- > Windows -- > Windows Service .
Then Create a New Project. It shows(Service1.cs),


 Then Right Click and  Click the Add Installer bar, ProjectInstaller.cs File will be created



Its having  two controls,  ServiceProcessInstaller1, and ServiceInstaller1

In ServiceProcessInstaller1 == > Go to Properties and Modify Account as Local Service . It is aoid the Set Service Login prompt being asked about the system username and password





In ServiceInstaller1 ==> Go to Properties and Modify StartType as Automatic , Servicename à Your Service Name , Display Name ( This name is shown in the Services), Description (This Name is shown in the Services)



Right Click Windows Service Project and Add Folder and file called CommonBehaviours.cs

CommonBehaviours.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace WindowsService.Function
{
    public class WriteToFile
    {
        public void WriteToFile1()
        {
            string strDateTime = DateTime.Now.ToString();
            StreamWriter sw = new StreamWriter(Path.Combine("D:\\temp\\", "Suresh.txt"), true);
            sw.WriteLine(strDateTime);

            sw.Close();
        }
    }

}
Service1.cs
using System;
using System.ServiceProcess;
using System.Timers;
namespace TestWindowsService
{
    partial class Service1 : ServiceBase
    {   //Make the service at particular time period
        Timer TimerObj = new Timer(ConvertMinutesToMilliseconds(30));
        public Service1()
        {
            InitializeComponent();
        }
        protected override void OnStart(string[] args)
        {   // TODO: Add code here to start your service.
            TimerObj.Elapsed += new ElapsedEventHandler(OnElapsedTime);
            TimerObj.Enabled = true;
        }
        protected override void OnStop()
        {   // TODO: Add code here to perform any tear-down necessary to stop your service.
            TimerObj.Enabled = false;
        }
        protected void OnElapsedTime(object source, ElapsedEventArgs e)
        {  //Write the current datetime to the file
           WindowsService.Function.WriteToFile objWriteToFile = new WindowsService.Function.WriteToFile();
        }
        public static double ConvertMinutesToMilliseconds(double minutes)
        {
            return TimeSpan.FromMinutes(minutes).TotalMilliseconds;
        }
    }
}


How to start service in Code

Go to ServiceInstaller1 -- > Create an event , Write a code to start the service like shown below.




create Service Installer

Ritht Click the Projects Solution -- > Add New Project -- > Go to Other Project Types -- > Setup and Deployment -- > Choose the Setup



Then follow the below steps



Then Double Click the Application Folder
Then Double Click the Primary output (from your service name)

Press ok . Then see the Setup Properties F4 (need to setup like below).It shown like below



Manufacturer will come in path as "C:\Program Files\ManufacturerValue"
Title will come in Setup Wizard

The Right Click and go to the Properties Set the Configurateion dropdown and Configuration Manager to Release Mode

Then our Installation steps :





Then Click Next and Finally Complete the Installation (click Close)

Finally the services is shown below


Now the Service is created and run successfully right.

Comments (16)

On 3 September 2018 at 05:41 , sathya shri said...
This comment has been removed by the author.
 
On 22 September 2018 at 06:52 , Unknown said...
This comment has been removed by the author.
 
On 24 September 2018 at 01:54 , Unknown said...

Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.


rpa training in chennai | best rpa training in chennai | rpa training in chennai | rpa training in bangalore
rpa training in pune | rpa online training

 
On 8 October 2018 at 23:32 , Unknown said...

Superb. I really enjoyed very much with this article here. Really it is an amazing article I had ever read. I hope it will help a lot for all. Thank you so much for this amazing posts and please keep update like this excellent article. thank you for sharing such a great blog with us.

Data Science training in Chennai | Data science training in bangalore
Data science training in pune| Data science online training
Python training in Kalyan nagar

 
On 8 October 2018 at 23:58 , Unknown said...

Impressive. Your story always bring hope and new energy. Keep up the good work.
java training in chennai | java training in bangalore

java online training | java training in pune

 
On 9 October 2018 at 04:17 , saimouni said...

Nice tips. Very innovative... Your post shows all your effort and great experience towards your work Your Information is Great if mastered very well.
python training in rajajinagar
Python training in btm
Python training in usa

 
On 10 October 2018 at 23:53 , gowsalya said...

Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.Best Devops Training in pune
Devops interview questions and answers

 
On 22 November 2018 at 23:14 , Sherin Alfonsa said...

Mind blowing content!! Thanks for uploading
Selenium Training in Chennai
selenium Classes in chennai
iOS Training in Chennai
Digital Marketing Training in Chennai
Android Training
Android Training in Chennai
Big Data Training in Chennai

 
On 23 May 2020 at 18:52 , nisha said...

Great Blog. Each and every steps are Uniquely Created. and the Concept was easily able to understand.

Data Science Training Course In Chennai | Data Science Training Course In Anna Nagar | Data Science Training Course In OMR | Data Science Training Course In Porur | Data Science Training Course In Tambaram | Data Science Training Course In Velachery


 
On 9 June 2020 at 07:10 , saran said...

"Thanks for sharing this article. Really helpful for me..
Digital Marketing Training Course in Chennai | Digital Marketing Training Course in Anna Nagar | Digital Marketing Training Course in OMR | Digital Marketing Training Course in Porur | Digital Marketing Training Course in Tambaram | Digital Marketing Training Course in Velachery

"

 
On 22 July 2020 at 02:50 , Unknown said...

Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.

Java training in Chennai

Java training in Bangalore

Java training in Hyderabad

Java Training in Coimbatore

Java Online Training

 
On 22 August 2020 at 22:50 , jeni said...

Excellent Blog! I would like to thank for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. I wanted to thank you for this websites!

hardware and networking training in chennai

hardware and networking training in velachery

xamarin training in chennai

xamarin training in velachery

ios training in chennai

ios training in velachery

iot training in chennai

iot training in velachery

 
On 23 August 2020 at 03:42 , Jayalakshmi said...

It¦s truly a nice and helpful piece of info. I am satisfied that you simply shared this helpful information with us. Please keep us informed like this. Thanks for sharing.
sap training in chennai

sap training in tambaram

azure training in chennai

azure training in tambaram

cyber security course in chennai

cyber security course in tambaram

ethical hacking course in chennai

ethical hacking course in tambaram

 
On 23 August 2020 at 23:27 , shiny said...

I like the blog format as you create user engagement in the complete article. Thanks for the informative posts.



oracle training in chennai

oracle training in annanagar

oracle dba training in chennai

oracle dba training in annanagar

ccna training in chennai

ccna training in annanagar

seo training in chennai

seo training in annanagar

 
On 24 August 2020 at 00:31 , praveen said...

First i got a great blog .I will be interested in more similar topics. i see you got really very useful topics, i will be always checking your blog thanks.
hardware and networking training in chennai

hardware and networking training in porur

xamarin training in chennai

xamarin training in porur

ios training in chennai

ios training in porur

iot training in chennai

iot training in porur

 
On 5 December 2020 at 20:33 , lakshmik7410 said...

A very useful content indeed ! thanks for sharing with us!
data science training in chennai

ccna training in chennai

iot training in chennai

cyber security training in chennai

ethical hacking training in chennai