ServiceControllerStatus Enumerazione

Definizione

Indica lo stato corrente del servizio.

public enum class ServiceControllerStatus
public enum ServiceControllerStatus
type ServiceControllerStatus = 
Public Enum ServiceControllerStatus
Ereditarietà
ServiceControllerStatus

Campi

Nome Valore Descrizione
Stopped 1

Il servizio non è in esecuzione. Corrisponde alla costante Win32 SERVICE_STOPPED , definita come 0x00000001.

StartPending 2

Il servizio viene avviato. Corrisponde alla costante Win32 SERVICE_START_PENDING , definita come 0x00000002.

StopPending 3

Il servizio viene arrestato. Corrisponde alla costante Win32 SERVICE_STOP_PENDING , definita come 0x00000003.

Running 4

Il servizio è in esecuzione. Corrisponde alla costante Win32 SERVICE_RUNNING , definita come 0x00000004.

ContinuePending 5

Il servizio continua in sospeso. Corrisponde alla costante Win32 SERVICE_CONTINUE_PENDING , definita come 0x00000005.

PausePending 6

La sospensione del servizio è in sospeso. Corrisponde alla costante Win32 SERVICE_PAUSE_PENDING , definita come 0x00000006.

Paused 7

Il servizio viene sospeso. Corrisponde alla costante Win32 SERVICE_PAUSED , definita come 0x00000007.

Esempio

Nell'esempio seguente viene usata la ServiceController classe per controllare lo stato corrente del servizio TelNet. Se il servizio viene arrestato, l'esempio avvia il servizio. Se il servizio è in esecuzione, l'esempio arresta il servizio.

// 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)

Commenti

L'enumerazione ServiceControllerStatus viene utilizzata da un'istanza della ServiceController classe per indicare se un servizio esistente è in esecuzione, arrestato, sospeso o se un comando Start, Stop, Pause o Continue è in sospeso.

Si applica a

Vedi anche