対象となるインスタンスが参照するサービスのステータスを取得します。
Public ReadOnly Property Status As ServiceControllerStatus
[C#]
public ServiceControllerStatus Status {get;}
[C++]
public: __property ServiceControllerStatus get_Status();
[JScript]
public function get Status() : ServiceControllerStatus;
プロパティ値
サービスが実行中、停止、または一時中断しているかどうか、または開始、停止、一時中断、または続行コマンドが保留中かどうかを示す ServiceControllerStatus 値の 1 つ。
例外
例外の種類 | 条件 |
---|---|
Win32Exception | システム API へのアクセス中にエラーが発生しました。 |
解説
サービスの現在の状態を示すステータス。指定できる値には、状態変更コマンドが保留中かどうかを示す複数の値が含まれています。
使用例
[Visual Basic, C#, C++] ServiceController クラスを使用して、TelNet サービスの現在のステータスを確認する例を次に示します。サービスが停止している場合、このコードはサービスを開始します。サービスが実行中である場合は、そのサービスを停止します。
' Toggle the Telnet service -
' If it is started (running, paused, etc), stop the service.
' If it is stopped, start the service.
Dim sc As New ServiceController("Telnet")
Console.WriteLine("The Telnet service status is currently set to {0}", sc.Status)
If sc.Status.Equals(ServiceControllerStatus.Stopped) Or sc.Status.Equals(ServiceControllerStatus.StopPending) Then
' Start the service if the current status is stopped.
Console.WriteLine("Starting the Telnet service...")
sc.Start()
Else
' Stop the service if its status is not set to "Stopped".
Console.WriteLine("Stopping the Telnet service...")
sc.Stop()
End If
' Refresh and display the current service status.
sc.Refresh()
Console.WriteLine("The Telnet service status is now set to {0}.", sc.Status)
[C#]
// Toggle the Telnet service -
// If it is started (running, paused, etc), stop the service.
// If it is stopped, start the service.
ServiceController sc = new ServiceController("Telnet");
Console.WriteLine("The Telnet service status is currently set to {0}",
sc.Status.ToString());
if ((sc.Status.Equals(ServiceControllerStatus.Stopped)) ||
(sc.Status.Equals(ServiceControllerStatus.StopPending)))
{
// Start the service if the current status is stopped.
Console.WriteLine("Starting the Telnet service...");
sc.Start();
}
else
{
// Stop the service if its status is not set to "Stopped".
Console.WriteLine("Stopping the Telnet service...");
sc.Stop();
}
// Refresh and display the current service status.
sc.Refresh();
Console.WriteLine("The Telnet service status is now set to {0}.",
sc.Status.ToString());
[C++]
// Toggle the Telnet service -
// If it is started (running, paused, etc), stop the service.
// If it is stopped, start the service.
ServiceController *sc = new ServiceController("Telnet");
if (sc)
{
Console::WriteLine("The Telnet service status is currently set to {0}",
__box(sc->Status));
if ((sc->Status == (ServiceControllerStatus::Stopped)) ||
(sc->Status == (ServiceControllerStatus::StopPending)))
{
// Start the service if the current status is stopped.
Console::WriteLine("Starting the Telnet service...");
sc->Start();
}
else
{
// Stop the service if its status is not set to "Stopped".
Console::WriteLine("Stopping the Telnet service...");
sc->Stop();
}
// Refresh and display the current service status.
sc->Refresh();
Console::WriteLine("The Telnet service status is now set to {0}.",
__box(sc->Status));
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows NT Server 4.0, Windows NT Workstation 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
.NET Framework セキュリティ:
- 直前の呼び出し元の完全信頼。このメンバは、部分的に信頼されているコードから使用することはできません。詳細の参照先 : 部分信頼コードからのライブラリの使用
参照
ServiceController クラス | ServiceController メンバ | System.ServiceProcess 名前空間