Gratzy
Gratzy

Reputation: 2898

C# app.config files and UAC

I started out with my application writing the config to the registry like I did years back with UAC wasn't around.

Turned out this wasn't a good idea so I moved to the app.config file and found that this is having issues as well with UAC.

The configuration I have for the application is machine specific; individual users do not have their own configuration and the rest of the apps including the service all drive off the single configuration file.

If I try updating this file in the program files\myapp folder it gets denied.

What is everyone else doing for a scenario like this where there needs to be a single configuration file?

I should also mention that this configuration needs to be updated from within my applications.

Upvotes: 1

Views: 1719

Answers (4)

WraithNath
WraithNath

Reputation: 18013

I would use the Common Application Data folder, this is where most new applications store data which works with UAC.

You can get this with the following code:

Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)

To view all options for special folders you can check this link:

http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx

The most common options would be the following:

Application Data - The directory that serves as a common repository for application-specific data for the current roaming user.

Common Application Data - The directory that serves as a common repository for application-specific data that is used by all users.

Local Application Data - The directory that serves as a common repository for application-specific data that is used by the current, non-roaming user.

Upvotes: 2

Brian
Brian

Reputation: 7146

I had a similar need with a WPF application. What I do is the following:

  1. Install the application with a boiler-plate configuration file.
  2. When the app runs, it checks for a config file in the user's App Datadirectory for configuration files, if they're not present it copies the default boiler-plate config files from the install directory.
  3. I then do any first-run initialization stuff that is needed.

I started out using the .NET ConfigurationManager, but I switched over to a plain old XML files because it was simpler and my requirements were basic.

Upvotes: 0

PhonicUK
PhonicUK

Reputation: 13864

Any machine-wide configuration files should be stored in:

Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);

Files in Program Files shouldn't be modified except when the application is installed/updated.

Upvotes: 0

DaveShaw
DaveShaw

Reputation: 52798

You should be storing your users' settings in app.config you should be using user.config. Have a look here for more info.

Upvotes: 0

Related Questions