ServiceControllerStatus Enumeração

Definição

Indica o estado atual do serviço.

public enum class ServiceControllerStatus
public enum ServiceControllerStatus
type ServiceControllerStatus = 
Public Enum ServiceControllerStatus
Herança
ServiceControllerStatus

Campos

Name Valor Description
Stopped 1

O serviço não está a funcionar. Isto corresponde à constante Win32 SERVICE_STOPPED , que é definida como 0x00000001.

StartPending 2

O serviço está a começar. Isto corresponde à constante Win32 SERVICE_START_PENDING , que é definida como 0x00000002.

StopPending 3

O serviço está a parar. Isto corresponde à constante Win32 SERVICE_STOP_PENDING , que é definida como 0x00000003.

Running 4

O serviço está a funcionar. Isto corresponde à constante Win32 SERVICE_RUNNING , que é definida como 0x00000004.

ContinuePending 5

A continuação do serviço está pendente. Isto corresponde à constante Win32 SERVICE_CONTINUE_PENDING , que é definida como 0x00000005.

PausePending 6

A pausa do serviço está pendente. Isto corresponde à constante Win32 SERVICE_PAUSE_PENDING , que é definida como 0x00000006.

Paused 7

O serviço está pausado. Isto corresponde à constante Win32 SERVICE_PAUSED , que é definida como 0x00000007.

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.

Aplica-se a

Ver também