Get all Services on a System using VB.NET

How to Get all Services on a System using VB.NET.
  • 4650

ServiceController class defined in the System.ServiceProcess namespace is used to work with services. ServiceController.GetServices static method gets all services installed on a machine.

This code snippet demonstrates how to get all services installed on a machine and list them in a ListBox control.

Create a Windows Forms application, add a ListBox control onto the Form, add following code and call GetAllServices method on the Form's load event handler.

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

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.