Прочитать на английском Изменить

Поделиться через


ServiceType Enum

Definition

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Represents the type of the service.

This enumeration supports a bitwise combination of its member values.

C#
[System.Flags]
public enum ServiceType
Inheritance
ServiceType
Attributes

Fields

Name Value Description
KernelDriver 1

A Kernel device driver such as a hard disk or other low-level hardware device driver.

FileSystemDriver 2

A file system driver, which is also a Kernel device driver.

Adapter 4

A service for a hardware device that requires its own driver.

RecognizerDriver 8

A file system driver used during startup to determine the file systems present on the system.

Win32OwnProcess 16

A Win32 program that can be started by the Service Controller and that obeys the service control protocol. This type of Win32 service runs in a process by itself.

Win32ShareProcess 32

A Win32 service that can share a process with other Win32 services.

InteractiveProcess 256

A service that can communicate with the desktop.

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

The service type indicates how the service is used by the system. The ServiceController that passes commands to the service stores a value for the service type.

The value of a ServiceType instance represents a set of flags combined using the bitwise OR operator.

The creation of interactive services is not supported. To workaround this, you can create a non-interactive service and a separate control GUI application that communicates with the service using sockets or remoting.

Applies to

Продукт Версии
.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)

See also