ServiceController.Start Metod

Definition

Startar tjänsten.

Överlagringar

Name Description
Start()

Startar tjänsten och skickar inga argument.

Start(String[])

Startar en tjänst och skickar de angivna argumenten.

Start()

Källa:
ServiceController.cs
Källa:
ServiceController.cs
Källa:
ServiceController.cs
Källa:
ServiceController.cs

Startar tjänsten och skickar inga argument.

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

Undantag

Ett fel uppstod vid åtkomst till ett system-API.

Det gick inte att hitta tjänsten.

Exempel

I följande exempel används ServiceController klassen för att kontrollera om Alerter-tjänsten har stoppats. Om tjänsten stoppas startar exemplet tjänsten och väntar tills tjänststatusen har angetts till 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

Kommentarer

Du kan inte anropa Stop tjänsten förrän tjänstkontrollantens status är Running.

Se även

Gäller för

Start(String[])

Källa:
ServiceController.cs
Källa:
ServiceController.cs
Källa:
ServiceController.cs
Källa:
ServiceController.cs

Startar en tjänst och skickar de angivna argumenten.

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

Parametrar

args
String[]

En matris med argument som ska skickas till tjänsten när den startas.

Undantag

Ett fel uppstod vid åtkomst till ett system-API.

Det går inte att starta tjänsten.

args är null.

-eller-

En medlem i matrisen är null.

Kommentarer

Du kan inte anropa Stop tjänsten förrän tjänstkontrollantens status är Running.

Se även

Gäller för