My application is currently storing settings in an INI file under the current user’s profile ( C:\Documents and Settings\<CurrentUser>\Application Data\MyApplication\MySettings.ini under WinXP). But I’ve realised some of these settings are unique to the machine not the user and thus want (actually need) to save them in a single location for all users.
Is there a folder location on Windows XP (and up) where I can store user independent settings?
NOTE: I don’t want to store them in the same folder as my application nor do I want to store them in the registry.
I notice there is an “All Users” folder under “C:\Documents and Settings\”? Should I be storing under there?
Bonus Points: I’m more likely to award the answer to whoever can also tell me how to return this path from Windows in Delphi 7.
For XP, Windows provides SHGetFolderPath() to get a known location. The CSIDL that you’re looking for is
CSIDL_COMMON_APPDATA, described as:For Vista and later, this has been replaced with SHGetKnownFolderPath() although SHGetFolderPath() is still available as a wrapper function for that. If you use the real Vista call, you should use
FOLDERID_ProgramDatainstead ofCSIDL_COMMON_APPDATA.This link here seems to show a way of doing it.
It seems to boil down to this (treat this with circumspection, I don’t know Delphi that well):
This page provides a list of all the
CSIDL_*andFOLDERID_*values. Keep in mind you should be using these functions for your user-specific data as well, not hard-coded values like"C:\Documents and Settings\<CurrentUser>\Application Data\". It may be that different language versions of Windows use different directory names or it’s possible that users can freely move their data areas around.