I’m using a ServiceController to try to start and stop a service on XP. Each time the form loads I can either stop or start the services, but not both. If I use the start button to start the service, the stop button won’t work and vice versa.
Here’s the code. Any insights would be much appreciated.
Private Sub btnStartService_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStartService.Click
If (ServiceController1.Status.ToString <> “Running”) Then
ServiceController1.Start()
End If
End Sub
Private Sub btnStopService_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStopService.Click
If ServiceController1.Status.ToString <> “Stopped” Then
ServiceController1.Stop()
End If