Blubb1337 (03-06-2010),edhunter (06-23-2015),MJLover (03-07-2010),___x][GooD. (01-19-2011)
Creating A Windows Service In Vb.net
What is a Windows Service?
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 servicesOriginally Posted by MSDN Definitions
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
[php]
Global.My.MySettings
[/php]
To this
[php]
My.Settings
[/php]
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.
[IMG]https://i111.photobucke*****m/albums/n121/golmor/image1-3.jpg[/IMG]
Now Goto The Properties of Timer1 and change the Interval to 10000 (10 Seconds)
[IMG]https://i111.photobucke*****m/albums/n121/golmor/image2.jpg[/IMG]
Source Code For Timer 1
(Double Click Timer1)(Timer_Tick Event)
' This will be executed every 20 seconds
[php]
'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")
End If
ML.Source = "What you called your application (Service)"
' Write a Log
ML.WriteEntry("Service Log", "Log On For " & _
CStr(TimeOfDay), EventLogEntryType******rmation)
[/php]
In this part of the code
[php]
Protected Overrides Sub OnStart(ByVal args() As String)
End Sub
[/php]
Enable the timer
[php]
Timer1.Enabled = True
[/php]
And on service stop
[php]
Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop your service.
End Sub
[/php]
Disable the timer
[php]
Timer1.enabled = false
[/php]
Now create your application/Service to do whatever it is you would like it to, and your good to go
Virus Scan
Blubb1337 (03-06-2010),edhunter (06-23-2015),MJLover (03-07-2010),___x][GooD. (01-19-2011)
Doesn't seems to work on xp, as you said
Good tutorial btw
-Rest in peace leechers-
Your PM box is 100% full.