locked
app.config versus application settings RRS feed

  • Question

  • I just started using app.config to set certain settings for the application. I would like to give the user the ability to adjust.

    I'm able to read app.confgi without any issue but I'm finding it difficult to write new vales back. I then discovered application settings. Since I'm new .Net  I would like to know what is the best option for my needs.

    I'm storing approx. five string settings and I have no need to create new ones during runtime. I would like to give the user the ability to edit and save the settings for the next time the program is run.

    Friday, July 24, 2020 3:15 AM

Answers

  • the default settings provider only saves user scoped settings. application scoped settings in app.config are not saved. 

    if you want the users to be able to change settings, best approach is to have the settings user-scoped. see Manage application settings (.NET)

    If you indeed need to have global settings that are modifiable by users, you need to write your own settingsprovider. .Net 2.0 SDK comes with a RegistrySettingsProvider Sample you can use as reference. Suggested path for the settings would be your own subfolder under Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), provided your program's installer has changed the folder permission to be writable for all users (otherwise only admins can write to the folder). 



    Visual C++ MVP



    Friday, July 24, 2020 6:25 PM

All replies

  • You normally won't want users be able to edit App.config directly. Since the file is on the same folder as your EXE file, if you're not careful you could create new security weakness by allow virus infection from non-Administrator users.

    IMO the correct way is to read/write value from HKCU/Software/<your company>/<your software> registry hive. In this way not only you don't need special care for security settings, your settings will automatically be backed up by most backup solutions, and can be carried around with a roaming AD account.

    Friday, July 24, 2020 12:45 PM
    Answerer
  • the default settings provider only saves user scoped settings. application scoped settings in app.config are not saved. 

    if you want the users to be able to change settings, best approach is to have the settings user-scoped. see Manage application settings (.NET)

    If you indeed need to have global settings that are modifiable by users, you need to write your own settingsprovider. .Net 2.0 SDK comes with a RegistrySettingsProvider Sample you can use as reference. Suggested path for the settings would be your own subfolder under Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), provided your program's installer has changed the folder permission to be writable for all users (otherwise only admins can write to the folder). 



    Visual C++ MVP



    Friday, July 24, 2020 6:25 PM
  • Thank you for the responses.

    The application settings seems to be working well, thank you for the input.

    Monday, July 27, 2020 3:11 PM
  • Hi JRDumont,

    It seems that your problem has been solved, so please click the "Mark as Answer" Link at the bottom of the correct post(s), so that it will help other members to find the solution quickly if they face a similar issue.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, July 28, 2020 1:21 AM