Here is an empty service template. I reuse it a lot. Hope it helps. The settings at the very bottom are the most important about installer
Update the code (onstart, onstop, ontimer), change the name from EMPTYSERVICE and include in a service project, and copy the bin to install machine.
Then run, from .net command prompt, installutil -i nameofexe.exe
To uninstall just run installutil.exe -u nameofexe.exe
Code:Option Explicit On Imports System Imports System.Net Imports System.IO Imports System.Xml Imports System.Xml.XPath Imports System.Text Imports System.Timers Imports System.Configuration.ConfigurationSettings Imports System.Diagnostics Imports System.ComponentModel Imports System.ServiceProcess Imports System.Configuration.Install Imports System.Windows.Forms.Application Public Class EMPTY_SERVICE Inherits System.ServiceProcess.ServiceBase Friend WithEvents oTimer As System.Timers.Timer #Region " Component Designer generated code " Public Sub New() MyBase.New() ' This call is required by the Component Designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call End Sub 'UserService overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub ' The main entry point for the process <MTAThread()> _ Shared Sub Main() Dim ServicesToRun() As System.ServiceProcess.ServiceBase ' More than one NT Service may run within the same process. To add ' another service to this process, change the following line to ' create a second service object. For example, ' ' ServicesToRun = New System.ServiceProcess.ServiceBase () {New Service1, New MySecondUserService} ' ServicesToRun = New System.ServiceProcess.ServiceBase() {New EMPTY_SERVICE} System.ServiceProcess.ServiceBase.Run(ServicesToRun) End Sub 'Required by the Component Designer Private components As System.ComponentModel.IContainer ' NOTE: The following procedure is required by the Component Designer ' It can be modified using the Component Designer. ' Do not modify it using the code editor. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() ' 'EMPTY_SERVICE ' Me.ServiceName = "EMPTY_SERVICE" End Sub #End Region Protected Overrides Sub OnStart(ByVal args() As String) Try oTimer = New System.Timers.Timer AddHandler oTimer.Elapsed, AddressOf oTimer_HasElapsed oTimer.Interval = 5000 oTimer.Enabled = True Catch ex As Exception Stop End Try End Sub Protected Overrides Sub OnStop() Try oTimer.Enabled = False oTimer = Nothing Catch ex As Exception Stop End Try End Sub Public Sub oTimer_HasElapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Try System.Diagnostics.EventLog.WriteEntry("Application", "The test message " & Date.Now, Diagnostics.EventLogEntryType.Information) Catch ex As Exception Stop End Try End Sub End Class <RunInstallerAttribute(True)> _ Public Class ProjectInstaller Inherits Installer Private serviceInstaller As ServiceInstaller Private processInstaller As ServiceProcessInstaller Private otherServiceInstaller As ServiceInstaller Sub New() processInstaller = New ServiceProcessInstaller serviceInstaller = New ServiceInstaller processInstaller.Account = ServiceAccount.LocalSystem serviceInstaller.StartType = ServiceStartMode.Automatic serviceInstaller.ServiceName = "EMPTY_SERVICE" Installers.Add(serviceInstaller) Installers.Add(processInstaller) End Sub End Class


LinkBack URL
About LinkBacks




Reply With Quote

Bookmarks