A program, which is under the control of windows OS is called as Windows Service.
Ex:- Timer, Event log, File System Watcher
File NewProjectVisual C # Windows Windows Service project template.
Note:- Windows Service project template is available in Professional Edition. it is not available in Standard Edition.
(a) On Start () will be executed when service is about to start. (b)On Stop () will be executed when service is about to stop.
Interested in mastering .NET? Learn more about ".NET Training" in this blog post.
Start Settings Control panel Performance and Maintenance Administrative tools Services (or) Start Run Service. MSC
Step 1: Open windows service Project Template and write the code as required.
Step 2:- Add the installers and build the project to get an Exe file.
Step 3: Install the exe file with the help of INSTALLUTIL TOOL.
Step 4: Open Service and start the service
Develop a service to restrict the accessibility of calculator software, if the user trying to open the calculator then display a message like “ Your System is effected with virus Please shut down”
OBS:-
Open windows service project with project name WSI
Adding Timer Control into tool Box.
Open Tool Box
Right click inside of General Tab
choose Items
Timer (System. Timers) Place Timer in Windows service with Enabled = false;
Using System. Windows.Forms;
Code for Timer 1_ Elapsed event
{
Process [] p = process . Get Process ();
For (int I = 0; I < p. length; I ++)
{
If (p [i].Process Name . To Upper () = = “CALC”)
{
P[i].KILL();
Message Box.Show (“Your System is effected with virus please shutdown”);
Break;
}
}
//for Code for On Start ()
Event
{
Timer 1.Enabled = true;
}
Code for On Stop () Event
{
Timer 1.Enabled = false;
}
Build the Project (build menu Build Solution )
OBS:-
WS1 .exe is created under D: / C194 / WS1 / Bin/Debug folder with a Service called as ABC 1 Installing the Service Open.net command prompt Debug > install util – I ws1.exe The transacted install completed Service is installed with the name ABC 1 Staring the service Open Service (Start run service.MSC)
Note:- This step is required only when Service Contains a Message box.
Adding Installers:-
Open Service 1. Cs [Design]
Right-click inside the body
Add Installer
OBS:-
Two controls will be added Service Process Installer
Properties Account = Local System Service Installer properties Service name = abc 2 Build the project (Build build Solution) OBS:- Ws2.exe is created under D: / C 194 /ws2/bin/Debug folder with a Service called as ABC 2 Open.
Net command prompt Change to D:/c 194 /ws2/bin/Debug folder Install Util – I ws2.exe Open service (Start run services.msc) Sight click on ABC 2 start Then check C:/INET PUB/mail Root/Queue folder for a mail at 12:30
To access the service, a service controller class is required, which is the part of the Service process Assembly. Methods of the service controller class
Project Menu Add Reference System. Service Process
Using System. Service Process;
Code for GD Service Controller [] x;
Code for Formal_ load event
{
X = Service Controller . get Service ();
For (int I = 0; I < x. length; I ++)
List Box1.Items .Add (x [i]. Service. Controller);
}
Code for start button
{
Int I = list box1. Selected Index; X [i].Start ();
}
Code for stop button
{
Int I = list box1. Selected Index;
X [i].Stop();
}
(Or)
X [I = List Box 1. Selected Index] .Stop ();
You liked the article?
Like: 0
Vote for difficulty
Current difficulty (Avg): Medium
TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.