次の方法で共有


ServiceControllerStatus 列挙体

サービスの現在の状態を示します。

<Serializable>
Public Enum ServiceControllerStatus
[C#]
[Serializable]
public enum ServiceControllerStatus
[C++]
[Serializable]
__value public enum ServiceControllerStatus
[JScript]
public
   Serializable
enum ServiceControllerStatus

解説

ServiceControllerStatus クラスは、 ServiceController クラスのインスタンスによって使用され、既存のサービスが実行、停止、一時中断のいずれの状態にあるのか、または Start、Stop、Pause、Continue のいずれのコマンドが保留中であるのかを示します。

メンバ

メンバ名 説明
ContinuePending サービスの継続は保留中です。
Paused サービスは一時中断されています。
PausePending サービスの一時中断は保留中です。
Running サービスは実行中です。
StartPending サービスは開始中です。
Stopped サービスは実行されていません。
StopPending サービスは停止中です。

使用例

[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++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

名前空間: System.ServiceProcess

プラットフォーム: Windows NT Server 4.0, Windows NT Workstation 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

アセンブリ: System.Serviceprocess (System.Serviceprocess.dll 内)

参照

System.ServiceProcess 名前空間 | Status