ServiceController.GetServices Method

Definition

Retrieves the non-device driver services on a computer, and those that are not drivers.

Overloads

GetServices(String)

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

GetServices()

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

GetServices(String)

Source:
ServiceController.cs
Source:
ServiceController.cs
Source:
ServiceController.cs

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

public static System.ServiceProcess.ServiceController[] GetServices (string machineName);

Parameters

machineName
String

The computer from which to retrieve the services.

Returns

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

Exceptions

An error occurred when accessing a system API.

The machineName parameter has invalid syntax.

Remarks

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

See also

Applies to

.NET 9 (package-provided) e altre versioni
Prodotto Versioni
.NET Core 1.0, Core 1.1, 8 (package-provided), 9 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

GetServices()

Source:
ServiceController.cs
Source:
ServiceController.cs
Source:
ServiceController.cs

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

public static System.ServiceProcess.ServiceController[] GetServices ();

Returns

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

Exceptions

An error occurred when accessing a system API.

Examples

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

ServiceController[] scServices;
scServices = ServiceController.GetServices();

// Display the list of services currently running on this computer.

Console.WriteLine("Services running on the local computer:");
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);
      Console.WriteLine("    Display name:    {0}", scTemp.DisplayName);

      // Query WMI for additional information about this service.
      // Display the start name (LocalSystem, etc) and the service
      // description.
      ManagementObject wmiService;
      wmiService = new ManagementObject("Win32_Service.Name='" + scTemp.ServiceName + "'");
      wmiService.Get();
      Console.WriteLine("    Start name:      {0}", wmiService["StartName"]);
      Console.WriteLine("    Description:     {0}", wmiService["Description"]);
   }
}

Remarks

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.

See also

Applies to

.NET 9 (package-provided) e altre versioni
Prodotto Versioni
.NET Core 1.0, Core 1.1, 8 (package-provided), 9 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)