ServiceController를 사용하여 서비스 상태를 알아보자
*
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

 

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

 

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

 

 

이 게시물을

댓글'2'
교교
  • 2014.03.10
  • 수정: 2014.03.10 08:32:44
System.ServiceProcess.dll.

The confusing thing is that this assembly is not in C:\Program Files\Reference Assemblies\Microsoft\Framework. It should be be in the GAC; however, it might not show in the list of assemblies. You can browse to C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 and reference it from there.

이 댓글을

공유하기

SEARCH

MENU NAVIGATION