Settings for Windows Service

G

Guest

I have a requirement to create a windows service application that will need
have settings (e.g. list values, connection settings, etc.) stored externally
(i.e. not hard coded).

To allow administrators to manage the settings I'll be creating a windows
form application, very simple one, that will run in the system tray and when
a setting needs to change (once in a blue moon) the administrator can right
click and change/add a setting through a dialog window. The dialog will give
the user the ability to restart the service so the settings can be read by
the service at start up again.

Here is my question. To store the settings i'm inclined to add an app.config
to the windows service and have the windows form app read/save settings to
the config file. What is the most appropriate and proper way to handle
something like this?
 
B

Bryan Phillips

Your approach is the most appropriate and simplest way of handling the
settings.
 
Y

Yeliz

Demetr, you can use OpenMappedExeConfiguration to get the configuration file you want to modify.

ExeConfigurationFileMap map = new ExeConfigurationFileMap();
map.ExeConfigFilename = path;
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);

config.AppSettings.Settings["Server"].Value = ".";
config.Save(ConfigurationSaveMode.Modified);

EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com
 
Y

Yeliz

Demetr, you can use OpenMappedExeConfiguration to get the configuration file you want to modify.

ExeConfigurationFileMap map = new ExeConfigurationFileMap();
map.ExeConfigFilename = path;
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);

config.AppSettings.Settings["Server"].Value = ".";
config.Save(ConfigurationSaveMode.Modified);

EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top