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
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.
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 toC:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
and reference it from there.이 댓글을
http://www.dotnetheaven.com/article/servicecontroller-in-vb.net
servicecontrollersamplevbnet.zip
이 댓글을