Language: VB.NET
Windows Service Installer AutoStart
Public Class ProjectInstaller Private Const LOG_SOURCE As String = "Log" Private Const LOG_LOG As String = "Log" Private _mainEventLog As EventLog Public Sub New() MyBase.New() 'This call is required by the Component Designer. InitializeComponent() If Not EventLog.SourceExists(LOG_SOURCE) Then EventLog.CreateEventSource(LOG_SOURCE, LOG_LOG) End If 'Add initialization code after the call to InitializeComponent End Sub Private Sub ProjectInstaller_BeforeUninstall(ByVal sender As Object, ByVal e As System.Configuration.Install.InstallEventArgs) Handles Me.BeforeUninstall Dim servicename As String = "" Dim services As System.ServiceProcess.ServiceController() services = System.ServiceProcess.ServiceController.GetServices() Dim Found As Boolean = False For Each sc As ServiceController In services If String.Compare(servicename, sc.ServiceName, True) = 0 Then Found = True End If Next If Found Then Dim Controller As New ServiceController(servicename) If Controller.Status = ServiceControllerStatus.Running Then Controller.Stop() End If End If End Sub Private Sub ProjectInstaller_Committed(ByVal sender As Object, ByVal e As System.Configuration.Install.InstallEventArgs) Handles Me.Committed Dim servicename As String = "" Dim services As System.ServiceProcess.ServiceController() services = System.ServiceProcess.ServiceController.GetServices() Dim Found As Boolean = False For Each sc As ServiceController In services If String.Compare(servicename, sc.ServiceName, True) = 0 Then Found = True End If Next If Found Then Dim Controller As New ServiceController(servicename) If Controller.Status = ServiceControllerStatus.Stopped Then Controller.Start() End If End If End Sub End Class
Tags:
Report Abuse
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search

