ServiceController.GetServices Method ()

 

Retrieves all the services on the local computer, except for the device driver services.

Namespace:   System.ServiceProcess
Assembly:  System.ServiceProcess (in System.ServiceProcess.dll)

Public Shared Function GetServices As ServiceController()

Return Value

Type: System.ServiceProcess.ServiceController()

An array of type ServiceController in which each element is associated with a service on the local computer.

Exception Condition
Win32Exception

An error occurred when accessing a system API.

GetServices returns only the non-device driver services and the services that are not drivers from the local computer. To retrieve device driver services, call the GetDevices method. Together, the two methods provide access to all the services on a computer.

The following example uses the ServiceController class to display the services that are running on the local computer.


Dim scServices() As ServiceController
scServices = ServiceController.GetServices()

' Display the list of services currently running on this computer.
Console.WriteLine("Services running on the local computer:")

Dim scTemp As ServiceController
For Each scTemp In  scServices

   If scTemp.Status = ServiceControllerStatus.Running Then
      ' Write the service name and the display name
      ' for each running service.
      Console.WriteLine()
      Console.WriteLine("  Service :        {0}", scTemp.ServiceName)
      Console.WriteLine("    Display name:    {0}", scTemp.DisplayName)

      ' Query WMI for additional information about this service.
      ' Display the start name (LocalSytem, etc) and the service
      ' description.
      Dim wmiService As ManagementObject
      wmiService = New ManagementObject("Win32_Service.Name='" + scTemp.ServiceName + "'")
      wmiService.Get()
      Console.WriteLine("    Start name:      {0}", wmiService("StartName"))
      Console.WriteLine("    Description:     {0}", wmiService("Description"))
   End If

Next scTemp

.NET Framework
Available since 1.1
Return to top
Show: