ServiceController.Start メソッド

定義

サービスを開始します。

オーバーロード

Start()

引数を渡さずに、サービスを開始します。

Start(String[])

指定した引数を渡して、サービスを開始します。

Start()

ソース:
ServiceController.cs
ソース:
ServiceController.cs
ソース:
ServiceController.cs
ソース:
ServiceController.cs

引数を渡さずに、サービスを開始します。

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

例外

システム API にアクセス中にエラーが発生しました。

サービスが見つかりませんでした。

次の例では、 クラスを ServiceController 使用して、Alerter サービスが停止されているかどうかを確認します。 サービスが停止した場合、この例ではサービスを開始し、サービスの状態が に 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

注釈

サービス コントローラーの状態Runningが になるまで、サービスの を呼び出Stopすことはできません。

こちらもご覧ください

適用対象

Start(String[])

ソース:
ServiceController.cs
ソース:
ServiceController.cs
ソース:
ServiceController.cs
ソース:
ServiceController.cs

指定した引数を渡して、サービスを開始します。

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

パラメーター

args
String[]

サービスを開始するときに、サービスに渡す引数の配列。

例外

システム API にアクセス中にエラーが発生しました。

サービスは開始できません。

argsnullです。

- または -

配列のメンバーが null です。

注釈

サービス コントローラーの状態Runningが になるまで、サービスの を呼び出Stopすことはできません。

こちらもご覧ください

適用対象