To delay a service use RequestAdditionalTime(nnnn); in the start method of the service where nnnn is milliseconds. Disable would be to stop the service.
Whatever you need to do should be wrapped in a class e.g.
Option Infer On
Imports System.ServiceProcess
Public Class WindowsServices
Public Sub StopService(pServiceName As String)
Dim sc = ServiceController.GetServices().
FirstOrDefault(Function(serviceController) serviceController.ServiceName = pServiceName)
If sc Is Nothing Then
Return
End If
If sc.Status = ServiceControllerStatus.Running Then
Try
sc.Stop()
sc.WaitForStatus(ServiceControllerStatus.Stopped)
Catch e1 As InvalidOperationException
' TODO
End Try
End If
End Sub
Public Sub StartService(pServiceName As String)
Dim sc = ServiceController.GetServices().
FirstOrDefault(Function(serviceController) serviceController.ServiceName = pServiceName)
If sc Is Nothing Then
Return
End If
sc.ServiceName = pServiceName
If sc.Status = ServiceControllerStatus.Stopped Then
Try
sc.Start()
sc.WaitForStatus(ServiceControllerStatus.Running)
Catch e1 As InvalidOperationException
' here for debug purposes
End Try
End If
End Sub
''' <summary>
''' Determine if service is currently installed
''' </summary>
''' <param name="pServiceName"></param>
''' <returns></returns>
Public Function IsInstalled(pServiceName As String) As Boolean
Dim sc = ServiceController.GetServices().
FirstOrDefault(Function(service) service.ServiceName = pServiceName)
Return (sc IsNot Nothing)
End Function
''' <summary>
''' provides the service status by string
''' </summary>
''' <param name="pServiceName"></param>
''' <returns></returns>
''' <remarks>
''' Example usage, set the text of a text box
''' in a form status-bar.
''' </remarks>
Public Function Status(pServiceName As String) As String
Dim serviceStatus = "Not installed"
Dim sc = ServiceController.GetServices().
FirstOrDefault(Function(serviceController) serviceController.ServiceName = pServiceName)
If sc Is Nothing Then
Return serviceStatus
End If
Select Case sc.Status
Case ServiceControllerStatus.Running
serviceStatus = "Running"
Case ServiceControllerStatus.Stopped
serviceStatus = "Stopped"
Case ServiceControllerStatus.Paused
serviceStatus = "Paused"
Case ServiceControllerStatus.StopPending
serviceStatus = "Stopping"
Case ServiceControllerStatus.StartPending
serviceStatus = "Starting"
Case Else
serviceStatus = "Status Changing"
End Select
Return serviceStatus
End Function
End Class
What I've done is package everything into a utility app (done in C#)