ServiceControllerStatus Enumeráció

Definíció

A szolgáltatás aktuális állapotát jelzi.

public enum class ServiceControllerStatus
public enum ServiceControllerStatus
type ServiceControllerStatus = 
Public Enum ServiceControllerStatus
Öröklődés
ServiceControllerStatus

Mezők

Name Érték Description
Stopped 1

A szolgáltatás nem fut. Ez a Win32-állandónak SERVICE_STOPPED felel meg, amely 0x00000001 néven van definiálva.

StartPending 2

A szolgáltatás elindul. Ez a Win32-állandónak SERVICE_START_PENDING felel meg, amely 0x00000002.

StopPending 3

A szolgáltatás leáll. Ez a Win32-állandónak SERVICE_STOP_PENDING felel meg, amely 0x00000003 definiálva.

Running 4

A szolgáltatás fut. Ez a Win32-állandónak SERVICE_RUNNING felel meg, amelyet 0x00000004 definiálunk.

ContinuePending 5

A szolgáltatás folytatása függőben van. Ez a Win32-állandónak SERVICE_CONTINUE_PENDING felel meg, amely 0x00000005 ként van definiálva.

PausePending 6

A szolgáltatás szüneteltetése függőben van. Ez a Win32-állandónak SERVICE_PAUSE_PENDING felel meg, amelyet 0x00000006 definiálunk.

Paused 7

A szolgáltatás szüneteltetve van. Ez a Win32-állandónak SERVICE_PAUSED felel meg, amely 0x00000007 ként van definiálva.

Példák

Az alábbi példa az ServiceController osztály használatával ellenőrzi a TelNet szolgáltatás aktuális állapotát. Ha a szolgáltatás leáll, a példa elindítja a szolgáltatást. Ha a szolgáltatás fut, a példa leállítja a szolgáltatást.

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

Megjegyzések

Az ServiceControllerStatus osztály egy példánya ServiceController az enumerálást használja annak jelzésére, hogy egy meglévő szolgáltatás fut-e, le van-e állítva, szüneteltetve van-e, vagy függőben van-e a Start, a Stop, a Pause vagy a Continue parancs.

A következőre érvényes:

Lásd még