In which directory should an application store its configuration files?
In Vista I see:
\Users\UserName\AppData\Local
\Users\UserName\AppData\LocalLow
\Users\UserName\AppData\Roaming
But I have no idea what is the difference on each one.Nor do I know what is the correct way to get them from a program. Are they on the registry or is there an api function to get those directories?
Where can I get this information not only for vista, but for XP.
None of the above.
An application should store ALL it's files in it own folder.
A user should be able to pick up that folder and plop it on another drive or another computer and have it run flawlessly.
In other words, use an ini file in the apps folder, not the registry.
If you want to support multiple users, make an ini file section or a separate ini file for each user.
That's the way it SHOULD work, despite microsofts insanity.
Just my two cents worth.
Portable is generally better for smaller apps. But if you want to save setting in the user's documents/applications dir, there are some APIs to get them. Then you essentially have multi-user functionality.
I've never used it, but a quick msdn search makes me think SHGetFolderPath is the right for the job.
SHGetFolderPath (http://msdn.microsoft.com/en-us/library/bb762181(VS.85).aspx) allows you to get the correct locations for various folders, which differ on each version of windows. You can select which is the most appropriate from http://msdn.microsoft.com/en-us/library/bb762494(VS.85).aspx
That said, for program settings, you're supposed to use the registry - "HKCU\Software\Company\Application\" is the preferred location.
And you're supposed to use .net and C++
For smaller/portable apps, it's better to keep different ini files named after the current username. (in the current folder)
So you just check for username.ini on startup or create it if it doesn't exist. And users can easily bakup their settings,restore to the defaults by deleting the ini, change the ini manually if needed, share settings between them easily etc etc.
Thank you all.
Hi xanatose,
You can also use environment variables to specify those directories. An example :
%appdata% = C:\Documents and Settings\UserName\Application Data