ServiceController.ExecuteCommand(Int32) Yöntem

Tanım

Hizmette özel bir komut yürütür.

public:
 void ExecuteCommand(int command);
public void ExecuteCommand (int command);
member this.ExecuteCommand : int -> unit
Public Sub ExecuteCommand (command As Integer)

Parametreler

command
Int32

Yürütülecek özel komutu gösteren uygulama tanımlı komut bayrağı. Değer 128 ile 256 (dahil) arasında olmalıdır.

Özel durumlar

Sistem API'lerine erişilirken bir hata oluştu.

Hizmet bulunamadı.

Örnekler

Aşağıdaki kod örneği, hizmet örneğinde özel komutları yürütmek için yönteminin SimpleService kullanımını ServiceController.ExecuteCommand(Int32) gösterir.

using System;
using System.ServiceProcess;

namespace test_exec_cmnd
{
    class Program
    {
        private enum SimpleServiceCustomCommands { StopWorker = 128, RestartWorker, CheckWorker };
        static void Main(string[] args)
        {
            ServiceController myService = new ServiceController("SimpleService");
            myService.ExecuteCommand((int)SimpleServiceCustomCommands.StopWorker);
            myService.ExecuteCommand((int)SimpleServiceCustomCommands.RestartWorker);
            myService.ExecuteCommand((int)SimpleServiceCustomCommands.CheckWorker);
        }
    }
}
Imports System.ServiceProcess



Class Program
    
    Private Enum SimpleServiceCustomCommands
        StopWorker = 128
        RestartWorker
        CheckWorker '
    End Enum 'SimpleServiceCustomCommands

    Shared Sub Main(ByVal args() As String) 
        Dim myService As New ServiceController("SimpleService")
        myService.ExecuteCommand(Fix(SimpleServiceCustomCommands.StopWorker))
        myService.ExecuteCommand(Fix(SimpleServiceCustomCommands.RestartWorker))
        myService.ExecuteCommand(Fix(SimpleServiceCustomCommands.CheckWorker))
    
    End Sub
End Class

Açıklamalar

çağrısı ExecuteCommandyaptığınızda hizmetin durumu değişmez. Hizmet başlatıldıysa, durum olarak kalır Running. Hizmet durdurulduysa, durum olarak kalır ve bu şekilde devam eder Stopped. Özel komutu işlemek için hizmetin yöntemini geçersiz kılması OnCustomCommand ve parametresi tarafından command tanımlanan komut için bir işleyici sağlaması gerekir.

Şunlara uygulanır

Ayrıca bkz.