I am developing a small application in C # to "manipulate" windows services (specifically apache).
I have already managed to start, stop and other operations.
What I now want is to obtain the (messages) results that the service returns.
Example:
- I modify the config file of apache and I save it (any line) that obviously generates an error in configuration syntax.
- I try to start the apache service and it obviously does not start and the error "message" is logged in the windows event viewer.
What I want
Capture in my application and show it in a textbox that message returned by apache.
this is my code.
public void ManipularServicios(string serviceName, int Operation)
{
ServiceController sc = new ServiceController();
sc.ServiceName = serviceName;
try
{
switch (Operation)
{
case 1: sc.Stop(); ; break;
case 2: sc.Start(); break;
}
}
catch (InvalidOperationException e)
{
txtErrores.Text = e.Message;
}
}
The part of the Catch never runs even though the service does not start, which is supposed to be an error.