I've got a method I wrote with the intended purpose of restarting a service.
Since I can't find a restart() method of the ServiceController class, my approach was to stop the service and then start it using the stop and start methods. This doesnt seem to be working though...
Any thoughts? Below is the code I came up with...
As usual... thank you so much to those that are willing to help us newbs out
Public Function restartService(ByVal targetMachineName As String, ByVal srvcName As String)
Dim serv As New System.ServiceProcess.ServiceController(srvcName, targetMachineName)
For Each serv In System.ServiceProcess.ServiceController.GetServices()
If serv.ServiceName = srvcName Then
serv.Stop()
serv.WaitForStatus(ServiceProcess.ServiceControllerStatus.Stopped, System.TimeSpan.FromSeconds(45))
serv.Start()
Exit Function
End If
Next
End Function
Since I can't find a restart() method of the ServiceController class, my approach was to stop the service and then start it using the stop and start methods. This doesnt seem to be working though...
Any thoughts? Below is the code I came up with...
As usual... thank you so much to those that are willing to help us newbs out
Public Function restartService(ByVal targetMachineName As String, ByVal srvcName As String)
Dim serv As New System.ServiceProcess.ServiceController(srvcName, targetMachineName)
For Each serv In System.ServiceProcess.ServiceController.GetServices()
If serv.ServiceName = srvcName Then
serv.Stop()
serv.WaitForStatus(ServiceProcess.ServiceControllerStatus.Stopped, System.TimeSpan.FromSeconds(45))
serv.Start()
Exit Function
End If
Next
End Function