Where should I store machine-wide application settings for non-roaming users?
Asked Answered
S

2

7

I have a WPF application that must run for all users of a machine with the same settings. The settings must be read/write. I have previously been storing user configuration settings in CommonApplicationData, for example

var settingsFile = Path.Combine(Environment.GetFolderPath(
  Environment.SpecialFolder.CommonApplicationData),
    "[company]", "[product]", "settings.xml");

However I read this morning that CommonApplicationData is used for roaming profiles, meaning they are not machine specific. From what I can find, we have the following options for application data (source):

// Store application-specific data for the current roaming user.
// A roaming user works on more than one computer on a network.
// A roaming user's profile is kept on a server on the network and is loaded onto a system ' when the user logs on.
System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);


// Store in-common application-specific data that is used by all users.
System.Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);


// Store application-specific data that is used by the current, non-roaming user.
System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

To summarize, the options are

  • Single user, roaming
  • All users, roaming
  • Single user, non-roaming

What I need is all users, non-roaming. My initial thought is to chuck it all into the install folder, but that seems a little old-school?

Thoughts?

Steib answered 6/12, 2011 at 20:50 Comment(7)
Where did you read that CommonApplicationData is roaming? I find it a bit strange...Deangelis
I read it in Bill Wagner's book Effective C#. However that's the only place I can find this tidbit so maybe it's a rare mistake on Wagner's part, and I'd be very interested in hearing if I'm wrong about this.Steib
From the MSDN documentation: "The directory that serves as a common repository for application-specific data that is used by all users."Thundershower
Maybe I don't understand roaming properly, so perhaps this is obvious from that brief description, but what if one or more of those users is a roaming user?Steib
There is no default folder in the standard install of Windows where all users have write access. You'll have to create one yourself.Immunology
The write access isn't an issue, I'm granting write access in my installer. Thanks though :)Steib
Already an old post, but I use this solution with success #14752548Poussin
L
4

Here is a good explanation of the appdata folder and other items related to roaming user.

According to the MSDN Documentation:

CommonApplicationData is "the directory that serves as a common repository for application-specific data that is used by all users"

whereas

LocalApplicationData is "the directory that serves as a common repository for application-specific data that is used by the current, non-roaming user".

Loden answered 6/12, 2011 at 21:53 Comment(0)
M
0

My preference for this is Application Settings which can be application wide or per user as you wish per setting.

Moral answered 6/12, 2011 at 22:7 Comment(1)
Application scoped settings cannot be altered at runtime, so they're only suitable for values that never change. It might work for op, but probably not based on his specific question.Uxorious

© 2022 - 2024 — McMap. All rights reserved.