ServiceController.ExecuteCommand(Int32) Metoda

Definice

Spustí ve službě vlastní příkaz.

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

Parametry

command
Int32

Příznak příkazu definovaný aplikací, který označuje, který vlastní příkaz se má spustit. Hodnota musí být mezi 128 a 256 včetně.

Výjimky

Při přístupu k systémovému rozhraní API došlo k chybě.

Služba nebyla nalezena.

Příklady

Následující příklad kódu ukazuje použití ServiceController.ExecuteCommand(Int32) metody ke spouštění vlastních příkazů v příkladu SimpleService služby.

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

Poznámky

Při volání ExecuteCommandse stav služby nezmění. Pokud byla služba spuštěna, stav zůstane Running. Pokud byla služba zastavena, stav zůstane Stoppedatd. Pro zpracování vlastního příkazu musí služba přepsat metodu OnCustomCommand a poskytnout obslužnou rutinu pro příkaz identifikovaný parametrem command .

Platí pro

Viz také