views:

81

answers:

5

For several of our applications we use an application configuration file. It usually just stores some directory paths and a few universal settings. We usually save it in the application directory (C:/Program Files/MyAppName)

One problem we see is users want to edit this (from the application) while logged in as a user that doesn't have access to write to the directory. Our applications are commonly installed and initially configured as an admin, but mostly used by (several different) limited users.

Is there a good way to make the setting.xml file read/write accessible to all users? Or a good place to put it?

+2  A: 

C:\Documents and Settings\All Users\Application Data\<Your App> might be a decent place to consider.

Justin
A: 

Application data folder or moving to registry.

Andrejs Cainikovs
+1 for advocating Application Data, -1 for advocating the registry. How you can you be both progressive and regressive in the same answer? ;)
Adam Robinson
This is so called workaround if application data is no-no, but I doubt so :-)
Andrejs Cainikovs
A: 

How important is localization? If localization isn't a high priority, you can store the files in %allusersprofile%\Application Data\ - that's the appdata folder accessible to all user accounts, and will work regardless of where things are installed, but only on English operating system installs.

If you want to store a file in the local user's directory and give each user their own, you can use %appdata% - that one will be entirely localized. But, each user will need their own copy, so it won't work if you need a common configuration.

If you need it to both be common to all users, and be 100% localized, you need to do a bit more work. I tried to find something like %allusersappdata%, and while I can find references online to that string, I can't get it to work on my own system. The workaround I found was to pull up %appdata% to find the localized text for the words Application Data, then use that to browse to that subfolder under %allusersprofile% - a bit more complicated, but it's the most bulletproof way I can find to do it. Someone please correct me if there's a direct path you can use to get to that folder.

matthock
A: 

Pass CSIDL_COMMON_APPDATA to SHGetSpecialFolderPath to get the writable, shared root data directory. Given that you can create a directory for your company and application.

sean e
A: 

I would try this previous question.

Which says:

System.Environment.SpecialFolder.LocalApplicationData

If you are using .NET

Adam W