ServiceController.Start Metoda
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Uruchamia usługę.
Przeciążenia
| Nazwa | Opis |
|---|---|
| Start() |
Uruchamia usługę, przekazując bez argumentów. |
| Start(String[]) |
Uruchamia usługę, przekazując określone argumenty. |
Start()
- Źródło:
- ServiceController.cs
- Źródło:
- ServiceController.cs
- Źródło:
- ServiceController.cs
- Źródło:
- ServiceController.cs
Uruchamia usługę, przekazując bez argumentów.
public:
void Start();
public void Start();
member this.Start : unit -> unit
Public Sub Start ()
Wyjątki
Wystąpił błąd podczas uzyskiwania dostępu do interfejsu API systemu.
Nie można odnaleźć usługi.
Przykłady
W poniższym przykładzie użyto ServiceController klasy , aby sprawdzić, czy usługa alertów została zatrzymana. Jeśli usługa zostanie zatrzymana, przykład uruchamia usługę i czeka na ustawienie stanu usługi na Runningwartość .
// 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
Uwagi
Nie można wywołać Stop usługi, dopóki stan kontrolera usługi to Running.
Zobacz też
Dotyczy
Start(String[])
- Źródło:
- ServiceController.cs
- Źródło:
- ServiceController.cs
- Źródło:
- ServiceController.cs
- Źródło:
- ServiceController.cs
Uruchamia usługę, przekazując określone argumenty.
public:
void Start(cli::array <System::String ^> ^ args);
public void Start(string[] args);
member this.Start : string[] -> unit
Public Sub Start (args As String())
Parametry
- args
- String[]
Tablica argumentów, które mają być przekazywane do usługi po jej uruchomieniu.
Wyjątki
Wystąpił błąd podczas uzyskiwania dostępu do interfejsu API systemu.
Nie można uruchomić usługi.
Parametr args ma wartość null.
— lub —
Elementem członkowskim tablicy jest null.
Uwagi
Nie można wywołać Stop usługi, dopóki stan kontrolera usługi to Running.