ServiceType 枚举
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示服务的类型。
此枚举支持其成员值的按位组合。
public enum class ServiceType
[System.Flags]
public enum ServiceType
[<System.Flags>]
type ServiceType =
Public Enum ServiceType
- 继承
- 属性
字段
Adapter | 4 | 针对需要其自己的驱动程序的硬件设备的服务。 |
FileSystemDriver | 2 | 文件系统驱动程序,也是内核设备驱动程序。 |
InteractiveProcess | 256 | 一种可以与桌面进行通信的服务。 |
KernelDriver | 1 | 内核设备驱动程序,例如硬盘或其他低级别的硬件设备驱动程序。 |
RecognizerDriver | 8 | 在启动时使用的文件系统驱动程序,用于确定在系统中存在的文件系统。 |
Win32OwnProcess | 16 | 可由服务控制器启动,并且遵从服务控制协议的 Win32 程序。 此类型的 Win32 服务在某个进程中单独运行。 |
Win32ShareProcess | 32 | 可与其他 Win32 服务共享一个进程的 Win32 服务。 |
示例
以下示例使用 ServiceController 类在本地计算机上显示设备驱动程序服务。
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)
注解
服务类型指示系统如何使用该服务。 将 ServiceController 命令传递给服务的 存储服务类型的值。
ServiceType 实例的值表示使用按位 OR 运算符组合的一组标志。
不支持创建交互式服务。 若要解决此问题,可以创建一个非交互式服务和一个单独的控制 GUI 应用程序,该应用程序使用套接字或远程处理与服务通信。