ServiceControllerStatus 列舉
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
表示服務的目前狀態。
public enum class ServiceControllerStatus
public enum ServiceControllerStatus
type ServiceControllerStatus =
Public Enum ServiceControllerStatus
- 繼承
欄位
| 名稱 | 值 | Description |
|---|---|---|
| Stopped | 1 | 服務沒有運作。 這對應於 Win32 |
| StartPending | 2 | 服務要開始了。 這對應於 Win32 |
| StopPending | 3 | 服務正在停止。 這對應於 Win32 |
| Running | 4 | 服務正在運作。 這對應於 Win32 |
| ContinuePending | 5 | 服務繼續進行尚待安排。 這對應於 Win32 |
| PausePending | 6 | 服務暫停仍在等待中。 這對應於 Win32 |
| Paused | 7 | 禮拜暫停。 這對應於 Win32 |
範例
以下範例使用該 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 指令正在等待執行。