ServiceController.Start Metodo

Definizione

Avvia il servizio.

Overload

Nome Descrizione
Start()

Avvia il servizio, passando nessun argomento.

Start(String[])

Avvia un servizio passando gli argomenti specificati.

Start()

Avvia il servizio, passando nessun argomento.

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

Eccezioni

Si è verificato un errore durante l'accesso a un'API di sistema.

Il servizio non è stato trovato.

Esempio

Nell'esempio seguente viene utilizzata la ServiceController classe per verificare se il servizio Alerter è stato arrestato. Se il servizio viene arrestato, l'esempio avvia il servizio e attende che lo stato del servizio sia impostato su 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

Commenti

Non è possibile chiamare Stop il servizio finché lo stato del controller del servizio non è Running.

Vedi anche

Si applica a

Start(String[])

Avvia un servizio passando gli argomenti specificati.

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

Parametri

args
String[]

Matrice di argomenti da passare al servizio all'avvio.

Eccezioni

Si è verificato un errore durante l'accesso a un'API di sistema.

Impossibile avviare il servizio.

args è null.

oppure

Un membro della matrice è null.

Commenti

Non è possibile chiamare Stop il servizio finché lo stato del controller del servizio non è Running.

Vedi anche

Si applica a