ServiceController.Status 속성

정의

이 인스턴스에서 참조하는 서비스 상태를 가져옵니다.

public:
 property System::ServiceProcess::ServiceControllerStatus Status { System::ServiceProcess::ServiceControllerStatus get(); };
public System.ServiceProcess.ServiceControllerStatus Status { get; }
[System.ServiceProcess.ServiceProcessDescription("SPStatus")]
public System.ServiceProcess.ServiceControllerStatus Status { get; }
member this.Status : System.ServiceProcess.ServiceControllerStatus
[<System.ServiceProcess.ServiceProcessDescription("SPStatus")>]
member this.Status : System.ServiceProcess.ServiceControllerStatus
Public ReadOnly Property Status As ServiceControllerStatus

속성 값

ServiceControllerStatus

서비스가 실행되고 있는지, 중지되었는지 또는 일시 중지되었는지를 나타내거나 시작, 중지, 일시 중지 또는 계속 명령이 보류 중인지를 나타내는 ServiceControllerStatus 값 중 하나입니다.

특성

예외

시스템 API에 액세스할 때 오류가 발생했습니다.

서비스를 찾을 수 없습니다.

예제

다음 예제에서는 클래스를 ServiceController 사용하여 텔넷 서비스의 현재 상태를 확인합니다. 서비스가 중지되면 예제에서 서비스를 시작합니다. 서비스가 실행 중이면 서비스를 중지하는 예제입니다.

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

설명

상태는 서비스의 현재 상태를 나타냅니다. 가능한 값 집합에는 상태 변경 명령이 보류 중인지 여부를 나타내는 몇 가지가 포함됩니다.

적용 대상