I have a windows service that reads from a config file. I need to modify this config file prior to the application starting. How can I create a GUI that would handle the changes to the config file. I know that a service does not have a GUI per se, but I really just need something to modify some strings in the config file and then start the service.
+4
A:
You can open the configuration and manipulate it programatically...
Configuration cfg = ConfigurationManager.OpenExeConfiguration("your path here");
// perform unspeakable acts upon cfg using your GUI
cfg.Save();
Update to elaborate on comments:
Generally when I need to provide a UI for a service, I expose a wcf channel using a net.tcp endpoint, which does not require special priveledges, and write a simple tray icon app to talk to it. Quick and easy compared to previous strategies.
Sky Sanders
2010-05-26 22:21:20
Can I assume that this is in another GUI project or is this a form that can be hosted within the service project?
Jim Beam
2010-05-26 22:28:36
@Jim - I was getting the impression that you were avoiding the need for a service UI by manipulating it's configuration file via other means before starting it up. Of course you could create a GUI for your service but the mechanism is convoluted. A better and clear route is to expose a net.tcp wcf endpoint and control it with a separate app. But that doesnt fit into your requirements as stated. If you could simply write the service to be able to accept configuration commands while running, that is another story altogether....
Sky Sanders
2010-05-26 22:33:32
No, I basically need a UI that a user can modify while the service is in a stopped state. Closing the form would save the configuration and then it would be used the next time the service starts.
Jim Beam
2010-05-26 22:39:46
@Jim - ok, so a simple winforms app that uses ConfigurationManager to open the file would be your best bet. That way the configuration app could use ServiceController to shut down the service, munge the cfg, and then restart the service all in one stop.
Sky Sanders
2010-05-26 22:42:23
Yup, that makes sense. thanks
Jim Beam
2010-06-03 23:58:10