Imports System.ServiceProcess Public Class Main Shared oWindowsService As WindowsService = Nothing Public Sub New() End Sub Private Shared Sub Main() ' If this from the Windows Service If Not Environment.UserInteractive Then Dim loWindowsService As ServiceBase() loWindowsService = New ServiceBase() {New WindowsService()} ServiceBase.Run(loWindowsService) Else oWindowsService = New WindowsService() oWindowsService.Start() Console.ReadLine() oWindowsService.Stop2() End If End Sub End Class Partial Public Class WindowsService Inherits ServiceBase Public Sub New() CanStop = True CanShutdown = True CanPauseAndContinue = False End Sub Protected Overrides Sub OnStart(args As String()) ' startup code here 'Console.WriteLine("Done With OnStart"); End Sub Protected Overrides Sub OnStop() ' stop code here End Sub Protected Overrides Sub OnShutdown() ' TODO: There may be a bug in the .NET Framework in that this method ' is not being called on system shutdown for SYSTEM account services. ' Not sure when/if it will be fixed, but I'm putting code here to stop ' stuff on the off-chance that it will be called eventually. ' stop code here End Sub ' These 2 methods are only used when not runnning as a Service, for testing from a Console window. Public Sub Start() Me.OnStart(Nothing) End Sub Public Sub Stop2() Me.OnStop() End Sub End Class