ServiceType 枚举

定义

表示服务的类型。Represents the type of the service.

此枚举有一个 FlagsAttribute 属性,允许按位组合成员值。

public enum class ServiceType
[System.Flags]
public enum ServiceType
[<System.Flags>]
type ServiceType = 
Public Enum ServiceType
继承
ServiceType
属性

字段

Adapter 4

针对需要其自己的驱动程序的硬件设备的服务。A service for a hardware device that requires its own driver.

FileSystemDriver 2

文件系统驱动程序,也是内核设备驱动程序。A file system driver, which is also a Kernel device driver.

InteractiveProcess 256

一种可以与桌面进行通信的服务。A service that can communicate with the desktop.

KernelDriver 1

内核设备驱动程序,例如硬盘或其他低级别的硬件设备驱动程序。A Kernel device driver such as a hard disk or other low-level hardware device driver.

RecognizerDriver 8

在启动时使用的文件系统驱动程序,用于确定在系统中存在的文件系统。A file system driver used during startup to determine the file systems present on the system.

Win32OwnProcess 16

可由服务控制器启动,并且遵从服务控制协议的 Win32 程序。A Win32 program that can be started by the Service Controller and that obeys the service control protocol. 此类型的 Win32 服务在某个进程中单独运行。This type of Win32 service runs in a process by itself.

Win32ShareProcess 32

可与其他 Win32 服务共享一个进程的 Win32 服务。A Win32 service that can share a process with other Win32 services.

示例

下面的示例使用 ServiceController 类来显示本地计算机上的设备驱动程序服务。The following example uses the ServiceController class to display the device driver services on the local computer.

array<ServiceController^>^scDevices = ServiceController::GetDevices();
if ( scDevices->Length )
{
   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:" );

   for each (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) != (ServiceType)0 )
      {
         numAdapter++;
      }
      if ( (scTemp->ServiceType & ServiceType::FileSystemDriver) != (ServiceType)0 )
      {
         numFileSystem++;
      }
      if ( (scTemp->ServiceType & ServiceType::KernelDriver) != (ServiceType)0 )
      {
         numKernel++;
      }
      if ( (scTemp->ServiceType & ServiceType::RecognizerDriver) != (ServiceType)0 )
      {
         numRecognizer++;
      }
   }
   Console::WriteLine();
   Console::WriteLine(  "Total of {0} device driver services", scDevices->Length.ToString() );
   Console::WriteLine(  "  {0} are adapter drivers", numAdapter.ToString() );
   Console::WriteLine(  "  {0} are file system drivers", numFileSystem.ToString() );
   Console::WriteLine(  "  {0} are kernel drivers", numKernel.ToString() );
   Console::WriteLine(  "  {0} are file system recognizer drivers", numRecognizer.ToString() );
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);


Dim scDevices() As ServiceController
scDevices = ServiceController.GetDevices()

Dim numAdapter As Integer
Dim numFileSystem As Integer
Dim numKernel As Integer
Dim numRecognizer As Integer

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

Dim scTemp As ServiceController
For Each 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 And ServiceType.Adapter) <> 0 Then
      numAdapter = numAdapter + 1
   End If
   If (scTemp.ServiceType And ServiceType.FileSystemDriver) <> 0 Then
      numFileSystem = numFileSystem + 1
   End If
   If (scTemp.ServiceType And ServiceType.KernelDriver) <> 0 Then
      numKernel = numKernel + 1
   End If
   If (scTemp.ServiceType And ServiceType.RecognizerDriver) <> 0 Then
      numRecognizer = numRecognizer + 1
   End If

Next scTemp

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)

注解

服务类型指示系统使用服务的方式。The service type indicates how the service is used by the system. ServiceController 命令传递到服务的将存储服务类型的值。The ServiceController that passes commands to the service stores a value for the service type.

ServiceType 实例的值表示使用按位 "或" 运算符组合在一起的一组标志。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. 若要解决此问题,可以创建非交互式服务,并使用套接字或远程处理与服务进行通信的单独控件 GUI 应用程序。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.

适用于

另请参阅