ServiceControllerStatus 列舉

定義

表示服務的目前狀態。

public enum class ServiceControllerStatus
public enum ServiceControllerStatus
type ServiceControllerStatus = 
Public Enum ServiceControllerStatus
繼承
ServiceControllerStatus

欄位

名稱 Description
Stopped 1

服務沒有運作。 這對應於 Win32 SERVICE_STOPPED 常數,定義為 0x00000001。

StartPending 2

服務要開始了。 這對應於 Win32 SERVICE_START_PENDING 常數,定義為 0x00000002。

StopPending 3

服務正在停止。 這對應於 Win32 SERVICE_STOP_PENDING 常數,定義為 0x00000003。

Running 4

服務正在運作。 這對應於 Win32 SERVICE_RUNNING 常數,定義為 0x00000004。

ContinuePending 5

服務繼續進行尚待安排。 這對應於 Win32 SERVICE_CONTINUE_PENDING 常數,定義為 0x00000005。

PausePending 6

服務暫停仍在等待中。 這對應於 Win32 SERVICE_PAUSE_PENDING 常數,定義為 0x00000006。

Paused 7

禮拜暫停。 這對應於 Win32 SERVICE_PAUSED 常數,定義為 0x00000007。

範例

以下範例使用該 ServiceController 類別來檢查 TelNet 服務的當前狀態。 如果服務被停止,範例會啟動服務。 如果服務正在執行,範例會停止服務。

// Toggle the Telnet service - 
// If it is started (running, paused, etc), stop the service.
// If it is stopped, start the service.
ServiceController^ sc = gcnew ServiceController(  "Telnet" );
if ( sc )
{
   Console::WriteLine(  "The Telnet service status is currently set to {0}", sc->Status );
   if ( (sc->Status == (ServiceControllerStatus::Stopped) ) || (sc->Status == (ServiceControllerStatus::StopPending) ) )
   {
      // Start the service if the current status is stopped.
      Console::WriteLine(  "Starting the Telnet service..." );
      sc->Start();
   }
   else
   {
      // Stop the service if its status is not set to "Stopped".
      Console::WriteLine(  "Stopping the Telnet service..." );
      sc->Stop();
   }

   // Refresh and display the current service status.
   sc->Refresh();
   Console::WriteLine(  "The Telnet service status is now set to {0}.", sc->Status );

// Toggle the Telnet service -
// If it is started (running, paused, etc), stop the service.
// If it is stopped, start the service.
ServiceController sc = new ServiceController("Telnet");
Console.WriteLine("The Telnet service status is currently set to {0}",
                  sc.Status);

if ((sc.Status == ServiceControllerStatus.Stopped) ||
    (sc.Status == ServiceControllerStatus.StopPending))
{
   // Start the service if the current status is stopped.

   Console.WriteLine("Starting the Telnet service...");
   sc.Start();
}
else
{
   // Stop the service if its status is not set to "Stopped".

   Console.WriteLine("Stopping the Telnet service...");
   sc.Stop();
}

// Refresh and display the current service status.
sc.Refresh();
Console.WriteLine("The Telnet service status is now set to {0}.",
                   sc.Status);

' Toggle the Telnet service - 
' If it is started (running, paused, etc), stop the service.
' If it is stopped, start the service.
Dim sc As New ServiceController("Telnet")
Console.WriteLine("The Telnet service status is currently set to {0}", sc.Status)

If sc.Status.Equals(ServiceControllerStatus.Stopped) Or sc.Status.Equals(ServiceControllerStatus.StopPending) Then
   ' Start the service if the current status is stopped.
   Console.WriteLine("Starting the Telnet service...")
   sc.Start()
Else
   ' Stop the service if its status is not set to "Stopped".
   Console.WriteLine("Stopping the Telnet service...")
   sc.Stop()
End If

' Refresh and display the current service status.
sc.Refresh()
Console.WriteLine("The Telnet service status is now set to {0}.", sc.Status)

備註

ServiceControllerStatus列舉由類別的ServiceController實例用來表示現有服務是否正在執行、停止、暫停,或是有 Start、Stop、Pause 或 Continue 指令正在等待執行。

適用於

另請參閱