views:

830

answers:

4

When should the Windows Registry be used for per-user state, and when should we use the filesystem, particularly the user's AppData folder? (eg, C:\Users\USERNAME\AppData). Where does Isolated Storage come in?

Is there a pretty firm rule, or is it just a fuzzy thing, like "use the registry until it becomes too much data to store in the registry". or "use whatever you feel like using."

Are there Windows logo requirements that affect the decision?

If I use the AppData directory, how do I choose between Local, Roaming and LocalLow ?

edit: I just noticed these similar questions:

I will summarize replies.

+2  A: 

You might want to consider Isolated Storage.

BobbyShaftoe
ok, Thanks. Good information. Isolated Storage uses a subdir within AppData for the actual location. It is also nicely isolated. So I guess it comes down to a size-based decision. If it would require more than a few reg entries, then use isolated storage?
Cheeso
A: 

I don't know whether there is a firm rule, but but one thing to consider is that the registry is transacted -- it is safer for concurrent read/write operations. So, if your user data might be written by multiple threads at run time (or if you have multiple exe's in your product package), consider using the registry.

History: One reason (as I heard it) that MS went from .ini files to the registry was precisely to try to handle the concurrent access problem.

.Net (sort of) went back to .ini files in the form of xml .config files, however those config files are not supposed to be written to at runtime (or at least not if there is a chance of concurrent writers/readers).

More info: http://blogs.msdn.com/oldnewthing/archive/2007/11/26/6523907.aspx

JMarsch
the user config file is designed to be modified at runtime.
Greg Dean
+5  A: 

If you have a small number of key/value pairs and the values aren't big the registry is great - and you don't care about xcopy deployment - then use the registry (I know this isn't exact, but it's usually obvious when working with the registry becomes a pain).

If you want xcopy deployment the data must be in the same folder as the program obviously - but the program can be somewhere under the AppData folder, it doesn't have to be under "program files".

Use isolated storage only when you need it or have to use it - for example ClickOnce.

Otherwise use AppData\Roaming, use Local or LocalLow only if you have a good reason.

EDIT: Here is the difference between Roaming, Local and LocalLow:

Windows has a little known feature called "roaming profiles", the general idea is that in a cooperate environment with this feature enabled any user can use any computer.

When a user logs in his private settings are downloaded from the server and when he logs out his settings are uploaded back to the server (the actual process is more complicated, obviously).

Files in the User's "Roaming" folder in Vista or "Application Data" in XP move around with the user - so any settings and data should be stored there.

Files under "Local" and "LocalLow" in vista and "Local Settings" in XP do not, so it's a good place for temp files, things that are tied to the specific computer or data that can be recalculated.

In Vista, as part of the new security features we all know and love, you can have programs running in "low integrity mode" (for example IE in protected mode), those programs are running with reduced privileges and can't access files in the user's profile - except for files under the "LocalLow" folder.

So, in conclusion, files stored in "LocalLow" are inherently insecure and files in "Local"/"Local Settings" are likely to be unavailable in some large companies - so unless you have good reason and know exactly what you are doing go with "Roaming"/"Application Data".

Nir
Could you elaborate on AppData\Roaming vs. Local - why is it better?
Sergey Aldoukhov
Sergey, I've added the information you requested, I hope you find it useful
Nir
+1  A: 

Don't clutter up my Registry thank you.

Use isolated storage, thats what it's for.

See Was The Windows Registry a Good Idea? On Jeffs Blog...

Omar Kooheji