Retrieves all the services on the local computer, except for the device driver services.
| C# | Visual Basic |
public static ServiceController[] GetServices()
Public Shared Function GetServices As ServiceController()
An array of type ServiceController in which each element is associated with a service on the device.
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 device.
The following example uses the ServiceController class to display the services that are running on the local device.
CopyVB.NET
CopyC#
Dim scServices() As ServiceController scServices = ServiceController.GetServices() ' Display the list of services currently running on this device. Debug.WriteLine("Services running on the local device:") 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. Debug.WriteLine() Debug.WriteLine(" Service : {0}", scTemp.ServiceName) End If Next scTemp
ServiceController[] scServices; scServices = ServiceController.GetServices(); // Display the list of services currently running on this device. Debug.WriteLine("Services running on the local device:"); foreach (ServiceController scTemp in scServices) { if (scTemp.Status == ServiceControllerStatus.Running) { // Write the service name and the display name // for each running service. Console.WriteLine(); Console.WriteLine(" Service : {0}", scTemp.ServiceName); } }