interacting with windows service
-
Is there a way to retrieve the data from the service using ServiceController? 1) I've got exception while trying to execute custom commands on the service 2) How to obtain the return code after the external command executed? The service is LocalSystem one. I start and stop it from external console application without problems. But once I add external commands after the service has been started
sc.ExecuteCommand((int)Commands.Cmnd1);
the exception is being thrown that the service can not be manipulated.Чесноков
-
Is there a way to retrieve the data from the service using ServiceController? 1) I've got exception while trying to execute custom commands on the service 2) How to obtain the return code after the external command executed? The service is LocalSystem one. I start and stop it from external console application without problems. But once I add external commands after the service has been started
sc.ExecuteCommand((int)Commands.Cmnd1);
the exception is being thrown that the service can not be manipulated.Чесноков
-
Is there a way to retrieve the data from the service using ServiceController? 1) I've got exception while trying to execute custom commands on the service 2) How to obtain the return code after the external command executed? The service is LocalSystem one. I start and stop it from external console application without problems. But once I add external commands after the service has been started
sc.ExecuteCommand((int)Commands.Cmnd1);
the exception is being thrown that the service can not be manipulated.Чесноков
- You need to ensure the custom command code is between 128 and 256.Values below 128 correspond to system-reserved values and values up 256 are restricted. 2) It seems that there's no standart framework designed to send and receive data to windows service and back.It's only a few information on the internet for this problem but I believe that it shouldn't be difficult to implement communication with a service based on sockets or named pipes. [EDIT] You could also set
AutoLog
property ofServiceBase
class totrue
to gather information about custom commands execution from the eventlog.
Life is a stage and we are all actors!
modified on Tuesday, October 27, 2009 7:07 AM
- You need to ensure the custom command code is between 128 and 256.Values below 128 correspond to system-reserved values and values up 256 are restricted. 2) It seems that there's no standart framework designed to send and receive data to windows service and back.It's only a few information on the internet for this problem but I believe that it shouldn't be difficult to implement communication with a service based on sockets or named pipes. [EDIT] You could also set
-
- You need to ensure the custom command code is between 128 and 256.Values below 128 correspond to system-reserved values and values up 256 are restricted. 2) It seems that there's no standart framework designed to send and receive data to windows service and back.It's only a few information on the internet for this problem but I believe that it shouldn't be difficult to implement communication with a service based on sockets or named pipes. [EDIT] You could also set
AutoLog
property ofServiceBase
class totrue
to gather information about custom commands execution from the eventlog.
Life is a stage and we are all actors!
modified on Tuesday, October 27, 2009 7:07 AM
- They were starting from 0 actually (0,1,2, ...) 2) I needed custom commands to get the feedback from the service, the same as you call ordinary function and it returns some error code. Otherwise I will have to implement such other communication Looking into logs would sute only for visual inspection.
Чесноков
- You need to ensure the custom command code is between 128 and 256.Values below 128 correspond to system-reserved values and values up 256 are restricted. 2) It seems that there's no standart framework designed to send and receive data to windows service and back.It's only a few information on the internet for this problem but I believe that it shouldn't be difficult to implement communication with a service based on sockets or named pipes. [EDIT] You could also set
-
would you specify the type of exception? maybe you do not have sufficient privileges to execute the commands, for gaining privileged u should add a manifest file to your project
System.InvalidOperationException
Чесноков
-
- They were starting from 0 actually (0,1,2, ...) 2) I needed custom commands to get the feedback from the service, the same as you call ordinary function and it returns some error code. Otherwise I will have to implement such other communication Looking into logs would sute only for visual inspection.
Чесноков
As it's mentioned in the documentation here custom command codes should be only between 128 and 256:
The only values for a custom command that you can define in your application or use in OnCustomCommand are those between 128 and 256. Integers below 128 correspond to system-reserved values.
Just take a look to this sample that demonstrates this behavior. I haven't found almost nothing about sending and receiving that from service but after analyzing some service based apps like SQL Server Db engine I suppose they it uses TCP socket on port 1433 and named pipes to serve the clients.
Life is a stage and we are all actors!