閱讀英文

共用方式為


ServiceType 列舉

定義

代表服務的類型。

此列舉支援其成員值的位元組合。

C#
[System.Flags]
public enum ServiceType
繼承
ServiceType
屬性

欄位

名稱 Description
Adapter 4

硬體裝置的服務,需要其本身的驅動程式。

FileSystemDriver 2

檔案系統驅動程式,這也是核心裝置驅動程式。

InteractiveProcess 256

可與桌面通訊的服務。

KernelDriver 1

核心裝置驅動程式,例如硬碟或其他低階硬體裝置驅動程式。

RecognizerDriver 8

檔案系統驅動程式,用來在啟動期間判斷檔案系統存在於系統上。

Win32OwnProcess 16

Win32 程式,可由服務控制程式啟動且遵守服務控制通訊協定。 這種類型的 Win32 服務會在本身的處理序中執行。

Win32ShareProcess 32

Win32 服務,可以與其他 Win32 服務共用處理序。

範例

下列範例會 ServiceController 使用 類別,在本機電腦上顯示裝置磁碟機服務。

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);

備註

服務類型會指出系統如何使用服務。 將命令傳遞至服務的 會 ServiceController 儲存服務類型的值。

ServiceType 實例的值代表使用位 OR 運算子結合的一組旗標。

不支援建立互動式服務。 若要解決此問題,您可以建立非互動式服務和個別的控制 GUI 應用程式,以使用通訊端或遠端處理與服務通訊。

適用於

產品 版本
.NET Core 1.0, Core 1.1, 6, 7, 8, 9
.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

另請參閱