VB.NET
* Imports System.ServiceProcess

Public Class Form1

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

End Class 

1.png

 

* 리스트 박스에 시스템의 현재 서비스 상태를 보여 주는 예제이다

 

* 추가로 리스트 박스에서 선택한 서비스를 중지,실행 할수 있게 해보자