Storing and accessing user config files in C#

I'm got an application that I started out using the registry to store the config files then discovered that isn't the best idea with UAC and moved to app.config.  Problem is, that seems to be a big issue with UAC and user rights to the program files folder.  What is everyone else using to store user application config information? Oh also, this needs to be store by MACHINE not by user....  All users that log on that computer need to operate the same configuration. Thanks!
Who is Participating?
Vel EousConnect With a Mentor Research & Development ManagerCommented:
Very interesting list!  However, UAC still prevents file access to all the common area folders...


Open in new window

Unless you have some obscure policies, your user will be allowed access to modify files within some of those directories irrespective of your UAC setting level.
Vel EousResearch & Development ManagerCommented:
Take a look at the following Enum list, specifically the CommonApplicationData member:
sej69Author Commented:
Very interesting list!  However, UAC still prevents file access to all the common area folders...
Never miss a deadline with

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Todd GerbertIT ConsultantCommented:
If your application genuinely requires that all users share the same set of parameters (I would carefully consider this requirement, since doing so kinda defeats the point of having separate user accounts to some extent), then you have a couple options.

1) You can create a new folder off the root of C:, C:\YourProgramData for example, during installation and store settings there. I'm not 100% sure, but I believe that UAC won't be such a pain in the butt in this case (provided NTFS permissions are set correctly).

2) Continue using the registry and accept UAC as a fact of life.

3) Use app.config in C:\Program Files\YourApp to store settings, and again you'll have to accept you'll need to work with UAC. This would be my choice.

You can include a UAC manifest with your application indicating that administrative privileges are required to run it, so users will receive the UAC prompt when your application starts up; or, you can instruct users that if they wish to be able make changes to the settings they'll need to right-click the shortcut and choose "Run as Administrator..."

Otherwise, you can use P/Invoke with Windows API functions to request an elevated token only when needed; e.g. your program runs fine as a normal, non-elevated user until they click the "Save" button in the settings dialog.
Jacques Bourgeois (James Burger)PresidentCommented:
There are 2 kinds of configurations. User and Application. You can set each setting to either in the Settings tab when you create them.

Application settings are recorded in the application directory, which is usually restricted by UAC, and are thus readonly.

User settings however are moved to the user AppData directory when the application is first run by a given user. This directory is available to the user, so those settings are read-write.

This makes sense, because if the user changes a read-write setting, that might frustates all the other users that would like it to be set another.

So the solution is simply to decide on each user if it will be fixed and shared by everyone (Application setting), or if each user will be able to change it the way he wants (User setting).

If you want a given user to be able to change an application setting, you can always have an admin version of the application that is started as an admin and that can change the value in the xml file that is used for the configuration.
sej69Author Commented:
All Courses

From novice to tech pro — start learning today.