Window service property OnCustomCommand

  • Thread starter Thread starter Tony Johansson
  • Start date Start date
T

Tony Johansson

Hi!

In this example this OnCustomCommand listen to 5 different command that are
integer.
How can I send any of these integer to a service so it can rect and change
it's behaviour ?
I know only how I can start, stop,pause and such things

protected override void OnCustomCommand(int command)
{
switch ( command)
{
case (int)FreeSpaceCommands.MonitorDDrive:
_driveLetter = "D";
break;
case (int)FreeSpaceCommands.MonitorEDrive:
_driveLetter = "D";
break;
case (int)FreeSpaceCommands.IncreaseFreeSpaceMinimumBy10:
_minAcceptableFreespace += 10;
break;
case (int)FreeSpaceCommands.DecreaseFreeSpaceMinimumBy10:
_minAcceptableFreespace -= 10;
break;
case (int)FreeSpaceCommands.MonitorHourly:
_monitoringInterval = 3600000;
break;
}
}

enum FreeSpaceCommands
{
MonitorDDrive = 128,
MonitorEDrive = 129,
IncreaseFreeSpaceMinimumBy10 = 130,
DecreaseFreeSpaceMinimumBy10 = 131,
MonitorHourly = 132,
}

//Tony
 
In this example this OnCustomCommand listen to 5 different command that
are integer.
How can I send any of these integer to a service so it can rect and change
it's behaviour ?

Using the ServiceController.ExecuteCommand() method.
 
Jeff Johnson said:
Using the ServiceController.ExecuteCommand() method.


So Calling this ServiceController.ExecuteCommand() method can as I believe
only be done by using a program you can't for example not use any existing
tool or program in .NET.

It's easy to create such a program but the reason I ask is becuase it no
reason to reinvent the wheel if such a tool already
exist.

//Tony
 
So Calling this ServiceController.ExecuteCommand() method can as I believe
only be done by using a program you can't for example not use any existing
tool or program in .NET.

It's easy to create such a program but the reason I ask is becuase it no
reason to reinvent the wheel if such a tool already
exist.

I didn't realize that's what you were asking for. The sc.exe command-line
tool should be able to do this. I believe the "command" you want to use is
"control". I guess it would look like this:

sc control YourServiceName 12
 
Back
Top