ServiceController.Start Méthode

Définition

démarre le service.

Surcharges

Start()

Démarre le service sans passer d'arguments.

Start(String[])

Démarre un service en passant les arguments spécifiés.

Start()

Démarre le service sans passer d'arguments.

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

Exceptions

Une erreur s'est produite lors de l'accès à une API système.

Le service est introuvable.

Exemples

L’exemple suivant utilise la ServiceController classe pour vérifier si le service Alerter est arrêté. Si le service est arrêté, l’exemple démarre le service et attend que l’état du service soit défini Runningsur .

// 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

Remarques

Vous ne pouvez pas appeler Stop le service tant que l’état du contrôleur de service n’est Runningpas .

Voir aussi

S’applique à

Start(String[])

Démarre un service en passant les arguments spécifiés.

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

Paramètres

args
String[]

Tableau d'arguments à passer au service lorsqu'il démarre.

Exceptions

Une erreur s'est produite lors de l'accès à une API système.

Le service ne peut pas être démarré.

args a la valeur null.

  • ou - Un membre du tableau est null.

Remarques

Vous ne pouvez pas appeler Stop le service tant que l’état du contrôleur de service n’est Runningpas .

Voir aussi

S’applique à