ServiceController.Start Método

Definición

inicia el servicio.Starts the service.

Sobrecargas

Start()

Inicia el servicio sin pasar argumentos.Starts the service, passing no arguments.

Start(String[])

Inicia un servicio y pasa los argumentos especificados.Starts a service, passing the specified arguments.

Start()

Inicia el servicio sin pasar argumentos.Starts the service, passing no arguments.

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

Excepciones

Error de acceso a la API del sistema.An error occurred when accessing a system API.

No se encontró el servicio.The service was not found.

Ejemplos

En el ejemplo siguiente se usa la ServiceController clase para comprobar si se ha detenido el servicio de alerta.The following example uses the ServiceController class to check whether the Alerter service is stopped. Si se detiene el servicio, el ejemplo inicia el servicio y espera hasta que el estado del servicio se establezca en Running .If the service is stopped, the example starts the service and waits until the service status is set to 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

Comentarios

No se puede llamar al Stop servicio hasta que el estado del controlador de servicio sea Running .You cannot call Stop for the service until the service controller status is Running.

Consulte también

Se aplica a

Start(String[])

Inicia un servicio y pasa los argumentos especificados.Starts a service, passing the specified arguments.

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

Parámetros

args
String[]

Matriz de argumentos que se va a pasar al servicio cuando se inicie.An array of arguments to pass to the service when it starts.

Excepciones

Error de acceso a la API del sistema.An error occurred when accessing a system API.

No se puede iniciar el servicio.The service cannot be started.

args es null.args is null.

O bien-or- Un miembro de la matriz es null.A member of the array is null.

Comentarios

No se puede llamar al Stop servicio hasta que el estado del controlador de servicio sea Running .You cannot call Stop for the service until the service controller status is Running.

Consulte también

Se aplica a