Settings for Windows Service

  • Thread starter Thread starter Guest
  • Start date Start date
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?
 
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
 
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
 
Back
Top