What I Have Done
I am trying to implement ServiceBase.OnCustomCommand(int command) in a custom Windows Service called MyTestService, with custom command codes as done in this answer:
public enum MyCustomCommands { ExecuteScript = 128 };
I noticed it's common to start custom command values at 128.
I attempted to implement custom command codes like so:
public enum MyCustomCommandCodes
{
Test1 = 1,
Test2 = 2,
}
protected override void OnCustomCommand(int command)
{
switch (command)
{
case (int)MyCustomCommandCodes.Test1:
eventLog1.WriteEntry("Test1");
break;
case (int)MyCustomCommandCodes.Test2:
eventLog1.WriteEntry("Test2");
break;
default:
eventLog1.WriteEntry("default");
break;
}
}
I am calling OnCustomCommand using Window's command-line utility Service Control (SC).
When I enter sc control MyTestService 1, I found instead of calling case Test1, it actually stopped the service.
In my mind, this explains why people start command values at 128, it's to prevent overlap with codes already in use.
I would like to be able to see which control codes are already in use by a Windows service.
Two-part Question:
- Is there a way to query the list of all codes that are in use?
- If yes, is there also a way to query what each code actually does?