ServiceController.Start Метод

Определение

Запускает службу.

Перегрузки

Имя Описание
Start()

Запускает службу, передавая аргументы без аргументов.

Start(String[])

Запускает службу, передавая указанные аргументы.

Start()

Исходный код:
ServiceController.cs
Исходный код:
ServiceController.cs
Исходный код:
ServiceController.cs
Исходный код:
ServiceController.cs

Запускает службу, передавая аргументы без аргументов.

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

Исключения

Ошибка при доступе к системным API.

Служба не найдена.

Примеры

В следующем примере класс используется ServiceController для проверки остановки службы оповещений. Если служба остановлена, в примере запускается служба и ожидается, пока состояние службы не будет задано 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);

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

Комментарии

Вы не можете вызывать Stop службу до тех пор, пока не будет задано Runningсостояние контроллера службы.

См. также раздел

Применяется к

Start(String[])

Исходный код:
ServiceController.cs
Исходный код:
ServiceController.cs
Исходный код:
ServiceController.cs
Исходный код:
ServiceController.cs

Запускает службу, передавая указанные аргументы.

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

Комментарии

Вы не можете вызывать Stop службу до тех пор, пока не будет задано Runningсостояние контроллера службы.

См. также раздел

Применяется к