ServiceControllerStatus Wyliczenie

Definicja

Wskazuje bieżący stan usługi.

public enum class ServiceControllerStatus
public enum ServiceControllerStatus
type ServiceControllerStatus = 
Public Enum ServiceControllerStatus
Dziedziczenie
ServiceControllerStatus

Pola

ContinuePending 5

Trwa kontynuowanie usługi. Odpowiada to stałej Win32 SERVICE_CONTINUE_PENDING , która jest zdefiniowana jako 0x00000005.

Paused 7

Usługa jest wstrzymana. Odpowiada to stałej Win32 SERVICE_PAUSED , która jest zdefiniowana jako 0x00000007.

PausePending 6

Wstrzymanie usługi jest oczekujące. Odpowiada stałej Win32 SERVICE_PAUSE_PENDING , która jest zdefiniowana jako 0x00000006.

Running 4

Usługa jest uruchomiona. Odpowiada stałej Win32 SERVICE_RUNNING , która jest zdefiniowana jako 0x00000004.

StartPending 2

Usługa jest uruchamiana. Odpowiada to stałej Win32 SERVICE_START_PENDING , która jest zdefiniowana jako 0x00000002.

Stopped 1

Usługa nie jest uruchomiona. Odpowiada to stałej Win32 SERVICE_STOPPED , która jest zdefiniowana jako 0x00000001.

StopPending 3

Usługa jest zatrzymywana. Odpowiada to stałej Win32 SERVICE_STOP_PENDING , która jest zdefiniowana jako 0x00000003.

Przykłady

W poniższym przykładzie użyto ServiceController klasy , aby sprawdzić bieżący stan usługi TelNet. Jeśli usługa zostanie zatrzymana, przykład uruchomi usługę. Jeśli usługa jest uruchomiona, przykład zatrzymuje usługę.

// 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.ToString());

if  ((sc.Status.Equals(ServiceControllerStatus.Stopped)) ||
     (sc.Status.Equals(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.ToString());

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

Uwagi

Wyliczenie ServiceControllerStatus jest używane przez wystąpienie ServiceController klasy, aby wskazać, czy istniejąca usługa jest uruchomiona, zatrzymana, wstrzymana, czy też oczekujące polecenie Start, Stop, Pause lub Continue.

Dotyczy

Zobacz też