ServiceControllerStatus 列舉
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
指示服務的目前狀態。
public enum class ServiceControllerStatus
public enum ServiceControllerStatus
type ServiceControllerStatus =
Public Enum ServiceControllerStatus
- 繼承
欄位
ContinuePending | 5 | 服務繼續為暫止。 這會對應到 Win32 |
Paused | 7 | 暫停服務。 這會對應到 Win32 |
PausePending | 6 | 服務暫停為暫止。 這會對應到 Win32 |
Running | 4 | 服務正在執行。 這會對應到 Win32 |
StartPending | 2 | 服務正在啟動。 這會對應到 Win32 |
Stopped | 1 | 沒有執行服務。 這會對應到 Win32 |
StopPending | 3 | 服務正在停止。 這會對應到 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 命令是否擱置中。