ServiceControllerStatus Enumeráció
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
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
Mezők
| Name | Érték | Description |
|---|---|---|
| Stopped | 1 | A szolgáltatás nem fut. Ez a Win32-állandónak |
| StartPending | 2 | A szolgáltatás elindul. Ez a Win32-állandónak |
| StopPending | 3 | A szolgáltatás leáll. Ez a Win32-állandónak |
| Running | 4 | A szolgáltatás fut. Ez a Win32-állandónak |
| ContinuePending | 5 | A szolgáltatás folytatása függőben van. Ez a Win32-állandónak |
| PausePending | 6 | A szolgáltatás szüneteltetése függőben van. Ez a Win32-állandónak |
| Paused | 7 | A szolgáltatás szüneteltetve van. Ez a Win32-állandónak |
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.