ServiceController.Start Método

Definición

inicia el servicio.

Sobrecargas

Nombre Description
Start()

Inicia el servicio y no pasa ningún argumento.

Start(String[])

Inicia un servicio y pasa los argumentos especificados.

Start()

Source:
ServiceController.cs
Source:
ServiceController.cs
Source:
ServiceController.cs
Source:
ServiceController.cs

Inicia el servicio y no pasa ningún argumento.

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

Excepciones

Error al acceder a una API del sistema.

No se encontró el servicio.

Ejemplos

En el ejemplo siguiente se usa la ServiceController clase para comprobar si el servicio Alerter está detenido. Si el servicio se detiene, el ejemplo inicia el servicio y espera hasta que el estado del servicio esté establecido en 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

Comentarios

No puede llamar Stop al servicio hasta que el estado del controlador de servicio sea Running.

Consulte también

Se aplica a

Start(String[])

Source:
ServiceController.cs
Source:
ServiceController.cs
Source:
ServiceController.cs
Source:
ServiceController.cs

Inicia un servicio y pasa los argumentos especificados.

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 van a pasar al servicio cuando se inicia.

Excepciones

Error al acceder a una API del sistema.

No se puede iniciar el servicio.

args es null.

O bien

Un miembro de la matriz es null.

Comentarios

No puede llamar Stop al servicio hasta que el estado del controlador de servicio sea Running.

Consulte también

Se aplica a