Join date: 2011-10-28
Location: Tulsa, OK
|Subject: [Tutorial]Create Windows Service in Express Sat Dec 08, 2012 11:40 am|| |
Creating A Windows Service In Vb.net
What is a Windows Service?
|Originally Posted by MSDN Definitions|
Microsoft Windows services, formerly known as NT services, enable you to create long-running executable applications that run in their own Windows sessions. These services can be automatically started when the computer boots, can be paused and restarted, and do not show any user interface. These features make services ideal for use on a server or whenever you need long-running functionality that does not interfere with other users who are working on the same computer. You can also run services in the security context of a specific user account that is different from the logged-on user or the default computer account.
Note:Windows Services are not available on older machines running Windows 95,98 Or ME , Windows 2000, NT, XP, + all have the ability however (not that this should be an issue, Just letting you know that windows services
will not be Multi OS, only NT 4.0 and --->)
If you want your application to be a running process in the background, Windows Services is the best approach
Creating a Windows Service in VB.NET
Before Vb.net Performing this task was hard or limited to the C++ Guru's because it required System Level Processes and Procedures But with the ,net framework and VB.net this task is 1000 times easier and more achievable.
Note: The .net Framework will help us install and control Windows Service.
As always, Open Vb.net and follow along, It is the only way you will learn anything.
At this point you will realize you do not have the Windows Services Template, Why is that? © Microsoft does not offer a Windows Service Template for Express/Standard Editions.
Well, Thanks to a guy by the name of Luis , We can add a Microsoft Service Template to your list (file attached)
Once you have added the template, Create a New Windows Service Project Call it whatever you like and Press Ok
You will notice there are 3 errors, The error looking for sub main is a easy fix, double click on it, and pick the only sub in the listbox.
The Second and Third Errors are fixed by changing this
In both Instances
Now with that resolved , You should have a working Service Project.
Treat this as a Form, Right click on Service1.vb and View Designer, From there you can drag and drop your components as if it was a form.
So, Let's create your first Windows Service
First thing Your Service Will Need is a Timer , So goto your toolbox and Drag a Timer to your Windows Service Template.
Now Goto The Properties of Timer1 and change the Interval to 10000 (10 Seconds)
Source Code For Timer 1
(Double Click Timer1)(Timer_Tick Event)
' This will be executed every 20 seconds
'Create a New Instance for a Log
Dim ML As New EventLog()
'Check if a Event Log Exists
If Not ML.SourceExists("Whatever You Called Your Application") Then
' Create a Log
ML.CreateEventSource("Your Application", "Myservice Log")
ML.Source = "What you called your application (Service)"
' Write a Log
ML.WriteEntry("Service Log", "Log On For " & _
In this part of the code
Protected Overrides Sub OnStart(ByVal args() As String)
Enable the timer
Timer1.Enabled = True
And on service stop
Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop your service.
Disable the timer
Timer1.enabled = false
Now create your application/Service to do whatever it is you would like it to, and your good to go