ServiceController.Start 메서드

정의

서비스를 시작합니다.

오버로드

Start()

인수를 전달하지 않고 서비스를 시작합니다.

Start(String[])

지정된 인수를 전달하면서 서비스를 시작합니다.

Start()

인수를 전달하지 않고 서비스를 시작합니다.

public:
 void Start();
public void Start ();
member this.Start : unit -> unit
Public Sub Start ()

예외

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

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

예제

다음 예제에서는 클래스를 ServiceController 사용하여 Alerter 서비스가 중지되었는지 여부를 확인합니다. 서비스가 중지되면 이 예제에서는 서비스를 시작하고 서비스 상태가 설정 Running될 때까지 기다립니다.

// Check whether the Alerter service is started.
ServiceController^ sc = gcnew ServiceController;
if ( sc )
{
   sc->ServiceName =  "Alerter";
   Console::WriteLine(  "The Alerter service status is currently set to {0}", sc->Status );
   if ( sc->Status == (ServiceControllerStatus::Stopped) )
   {
      // Start the service if the current status is stopped.
      Console::WriteLine(  "Starting the Alerter service..." );
      try
      {
         // Start the service, and wait until its status is "Running".
         sc->Start();
         sc->WaitForStatus( ServiceControllerStatus::Running );
         
         // Display the current service status.
         Console::WriteLine(  "The Alerter service status is now set to {0}.", sc->Status );
      }
      catch ( InvalidOperationException^ e ) 
      {
         Console::WriteLine(  "Could not start the Alerter service." );
      }
   }
}

// Check whether the Alerter service is started.

ServiceController sc  = new ServiceController();
sc.ServiceName = "Alerter";
Console.WriteLine("The Alerter service status is currently set to {0}",
                   sc.Status.ToString());

if (sc.Status == ServiceControllerStatus.Stopped)
{
   // Start the service if the current status is stopped.

   Console.WriteLine("Starting the Alerter service...");
   try
   {
      // Start the service, and wait until its status is "Running".
      sc.Start();
      sc.WaitForStatus(ServiceControllerStatus.Running);

      // Display the current service status.
      Console.WriteLine("The Alerter service status is now set to {0}.",
                         sc.Status.ToString());
   }
   catch (InvalidOperationException)
   {
      Console.WriteLine("Could not start the Alerter service.");
   }
}

' Check whether the Alerter service is started.

Dim sc As New ServiceController()
sc.ServiceName = "Alerter"
Console.WriteLine("The Alerter service status is currently set to {0}", sc.Status)

If sc.Status = ServiceControllerStatus.Stopped Then
   ' Start the service if the current status is stopped.
   Console.WriteLine("Starting the Alerter service...")

   Try
      ' Start the service, and wait until its status is "Running".
      sc.Start()
      sc.WaitForStatus(ServiceControllerStatus.Running)
      
      ' Display the current service status.
      Console.WriteLine("The Alerter service status is now set to {0}.", sc.Status)
   Catch 
      Console.WriteLine("Could not start the Alerter service.")
   End Try
End If

설명

서비스 컨트롤러 상태가 Running될 때까지 서비스를 호출 Stop 할 수 없습니다.

추가 정보

적용 대상

Start(String[])

지정된 인수를 전달하면서 서비스를 시작합니다.

public:
 void Start(cli::array <System::String ^> ^ args);
public void Start (string[] args);
member this.Start : string[] -> unit
Public Sub Start (args As String())

매개 변수

args
String[]

서비스를 시작할 때 해당 서비스로 전달할 인수 배열입니다.

예외

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

서비스를 시작할 수 없습니다.

args이(가) null인 경우

또는 배열의 멤버가 null인 경우

설명

서비스 컨트롤러 상태가 Running될 때까지 서비스를 호출 Stop 할 수 없습니다.

추가 정보

적용 대상