ServiceController.ExecuteCommand(Int32) 메서드

정의

서비스에서 사용자 지정 명령을 실행합니다.

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

매개 변수

command
Int32

실행할 사용자 지정 명령을 나타내는 애플리케이션 정의 명령 플래그입니다. 값은 128 이상 256 이하여야 합니다.

예외

시스템 API에 액세스할 때 오류가 발생했습니다.

서비스를 찾을 수 없습니다.

예제

다음 코드 예제에서는 서비스 예제에서 사용자 지정 명령을 실행 하는 메서드의 SimpleService 사용을 ServiceController.ExecuteCommand(Int32) 보여 줍니다.

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

설명

호출 ExecuteCommand할 때 서비스의 상태는 변경되지 않습니다. 서비스가 시작된 경우 상태는 그대로 유지됩니다 Running. 서비스가 중지된 경우 상태는 그대로 유지 Stopped됩니다. 사용자 지정 명령을 처리하려면 서비스에서 메서드를 재정의 OnCustomCommand 하고 매개 변수로 식별된 command 명령에 대한 처리기를 제공해야 합니다.

적용 대상

추가 정보