ServiceController.GetDevices Method

Definition

Retrieves the device driver services on a computer.

Overloads

GetDevices()

Retrieves the device driver services on the local computer.

GetDevices(String)

Retrieves the device driver services on the specified computer.

GetDevices()

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

Retrieves the device driver services on the local computer.

C#
public static System.ServiceProcess.ServiceController[] GetDevices();

Returns

An array of type ServiceController in which each element is associated with a device driver 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 device driver services on the local computer.

C#
ServiceController[] scDevices;
scDevices = ServiceController.GetDevices();

int numAdapter = 0,
    numFileSystem = 0,
    numKernel = 0,
    numRecognizer = 0;

// Display the list of device driver services.
Console.WriteLine("Device driver services on the local computer:");

foreach (ServiceController scTemp in scDevices)
{
   // Display the status and the service name, for example,
   //   [Running] PCI Bus Driver
   //             Type = KernelDriver

   Console.WriteLine(" [{0}] {1}",
                     scTemp.Status, scTemp.DisplayName);
   Console.WriteLine("           Type = {0}", scTemp.ServiceType);

   // Update counters using the service type bit flags.
   if ((scTemp.ServiceType & ServiceType.Adapter) != 0)
   {
      numAdapter++;
   }
   if ((scTemp.ServiceType & ServiceType.FileSystemDriver) != 0)
   {
      numFileSystem++;
   }
   if ((scTemp.ServiceType & ServiceType.KernelDriver) != 0)
   {
      numKernel++;
   }
   if ((scTemp.ServiceType & ServiceType.RecognizerDriver) != 0)
   {
      numRecognizer++;
   }
}

Console.WriteLine();
Console.WriteLine("Total of {0} device driver services", scDevices.Length);
Console.WriteLine("  {0} are adapter drivers", numAdapter);
Console.WriteLine("  {0} are file system drivers", numFileSystem);
Console.WriteLine("  {0} are kernel drivers", numKernel);
Console.WriteLine("  {0} are file system recognizer drivers", numRecognizer);

Remarks

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

See also

Applies to

.NET 10 (package-provided) i inne wersje
Produkt Wersje
.NET Core 1.0, Core 1.1, 8 (package-provided), 9 (package-provided), 10 (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, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

GetDevices(String)

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

Retrieves the device driver services on the specified computer.

C#
public static System.ServiceProcess.ServiceController[] GetDevices(string machineName);

Parameters

machineName
String

The computer from which to retrieve the device driver services.

Returns

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

Exceptions

An error occurred when accessing a system API.

The machineName parameter has invalid syntax.

Remarks

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

See also

Applies to

.NET 10 (package-provided) i inne wersje
Produkt Wersje
.NET Core 1.0, Core 1.1, 8 (package-provided), 9 (package-provided), 10 (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, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)