ServiceControllerStatus Enumeração
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Indica o estado atual do serviço.
public enum class ServiceControllerStatus
public enum ServiceControllerStatus
type ServiceControllerStatus =
Public Enum ServiceControllerStatus
- Herança
Campos
| Name | Valor | Description |
|---|---|---|
| Stopped | 1 | O serviço não está a funcionar. Isto corresponde à constante Win32 |
| StartPending | 2 | O serviço está a começar. Isto corresponde à constante Win32 |
| StopPending | 3 | O serviço está a parar. Isto corresponde à constante Win32 |
| Running | 4 | O serviço está a funcionar. Isto corresponde à constante Win32 |
| ContinuePending | 5 | A continuação do serviço está pendente. Isto corresponde à constante Win32 |
| PausePending | 6 | A pausa do serviço está pendente. Isto corresponde à constante Win32 |
| Paused | 7 | O serviço está pausado. Isto corresponde à constante Win32 |
Exemplos
O exemplo seguinte utiliza a ServiceController classe para verificar o estado atual do serviço TelNet. Se o serviço for interrompido, o exemplo inicia o serviço. Se o serviço estiver a correr, o exemplo interrompe o serviço.
// 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)
Observações
A ServiceControllerStatus enumeração é usada por uma instância da ServiceController classe para indicar se um serviço existente está em funcionamento, parado, pausado, ou se um comando Start, Stop, Pause ou Continue está pendente.