I need to develop a Win32 service in Delphi XE and I need to find a way how to control it from the same machine (or eventually other machines in the LAN if possible). By controlling it I mean changing it's internal parameters implemented by me, not Windows service parameters. The service itself should not interact with the desktop. Could you please advise the best way how to do it?
You could use an IPC method like named pipes to communicate with the service or communicate with the service using a TCP socket.
I did it with Named pipes and it works like a charm.
I realize that this is pretty low tech, but you could actually just keep all the settings in the registry, and then the front-end GUI could write to them, and then the service could periodically check a single key called HKEY_LOCAL_MACHINE\Software\YourStuff\ConfigurationChangeCounter and if that value is different, re-read the configuration and apply it (perhaps restarting if necessary).
If you really need to do things other than configuration, then perhaps a TCP socket is lots better, but it's also lots of work to write yourself a custom TCP based protocol handler component and debug that.
But think about it; Your service needs to persist and read configuration anyways, why not just have it use the code it already has to accomplish this task. You can remotely connect to a machine and modify its registry values using standard windows tools, and in large corporate networks, such practices are already standard. Some service elements in Windows itself use this approach.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With