Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
GetAllServices()
End Sub
Private Sub GetAllServices()
For Each service As ServiceController In ServiceController.GetServices()
Dim serviceName As String = service.ServiceName
Dim serviceDisplayName As String = service.DisplayName
Dim serviceType As String = service.ServiceType.ToString()
Dim status As String = service.Status.ToString()
ListBox1.Items.Add(serviceName + " " + serviceDisplayName +
serviceType + " " + status)
Next
End Sub
Private Sub GetAllDevices()
For Each service As ServiceController In ServiceController.GetDevices()
Dim serviceName As String = service.ServiceName
Dim serviceDisplayName As String = service.DisplayName
Dim serviceType As String = service.ServiceType.ToString()
Dim status As String = service.Status.ToString()
ListBox1.Items.Add(serviceName + " " + serviceDisplayName +
serviceType + " " + status)
Next
End Sub
Private Sub StartStop()
Dim service As ServiceController = New ServiceController("MyServiceName")
If ((service.Status.Equals(ServiceControllerStatus.Stopped)) Or
(service.Status.Equals(ServiceControllerStatus.StopPending))) Then
service.Start()
Else
service.Stop()
End If
End Sub