ServiceController.Start Metódus
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Elindítja a szolgáltatást.
Túlterhelések
| Name | Description |
|---|---|
| Start() |
Elindítja a szolgáltatást, és nem ad át argumentumokat. |
| Start(String[]) |
Elindít egy szolgáltatást, átadva a megadott argumentumokat. |
Start()
- Forrás:
- ServiceController.cs
- Forrás:
- ServiceController.cs
- Forrás:
- ServiceController.cs
- Forrás:
- ServiceController.cs
Elindítja a szolgáltatást, és nem ad át argumentumokat.
public:
void Start();
public void Start();
member this.Start : unit -> unit
Public Sub Start ()
Kivételek
Hiba történt egy rendszer API elérésekor.
A szolgáltatás nem található.
Példák
Az alábbi példa az ServiceController osztály használatával ellenőrzi, hogy a riasztási szolgáltatás leállt-e. Ha a szolgáltatás leáll, a példa elindítja a szolgáltatást, és megvárja, amíg a szolgáltatás állapota be nem áll 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
Megjegyzések
A szolgáltatás csak akkor hívható megStop, ha a szolgáltatásvezérlő állapota .Running
Lásd még
A következőre érvényes:
Start(String[])
- Forrás:
- ServiceController.cs
- Forrás:
- ServiceController.cs
- Forrás:
- ServiceController.cs
- Forrás:
- ServiceController.cs
Elindít egy szolgáltatást, átadva a megadott argumentumokat.
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éterek
- args
- String[]
A szolgáltatásnak az indításkor átadandó argumentumok tömbje.
Kivételek
Hiba történt egy rendszer API elérésekor.
A szolgáltatás nem indítható el.
Megjegyzések
A szolgáltatás csak akkor hívható megStop, ha a szolgáltatásvezérlő állapota .Running