where to store the program settings (.ini)

Most comfortable (for me personallY) place where program must store the ini-file with options/settings is the application directory. For example, dbview.exe must save the dbview.ini in same folder where .exe is

But interface guide from Microsoft noted that these end-user settings must be saved in CSIDL_APPDATA (C:\Documents and Settings\<user>\Application Data\<Company>\<Application>)

If application ran in MS Vista with enabled UAC and tried to write (create file) something into application directory, error raised.

So we changed the code (to get the file name for settings):
function GetINIFileName: string;
var
  strFileName: string;
begin
  strFileName := ExtractFileName(ParamStr(0));
  Result := GetUserDirectory(‘Scalabium\’ + ChangeFileExt(strFileName, ”) + ‘\’) + ChangeFileExt(strFileName, ‘.ini’)
end;

where
function GetUserDirectory(const SubDir: string): string;
var
  List: PItemIDList;
  Path: array[0..MAX_PATH] of Char;
begin
  SHGetSpecialFolderLocation(0, CSIDL_APPDATA, List);
  SHGetPathFromIDList(List, Path);
  Result := String(Path);
  if (Result = ”) then
    Result:= ExtractFilePath(ParamStr(0))
  else
  if (SubDir <> ”) then
  begin
    Result := Result + ‘\’ + SubDir;

    ForceDirectories(Result);
  end
end;

One Response to “where to store the program settings (.ini)”

  1. shkolnik says:

    Why I prefer to store the ini-file in application directory:
    1. I may have a few directories with same application (.exe) but different settings. Very useful for me (debug, for example)
    2. I can easy transfer the changed application from one computer into another. All files (data, sources, exe, configurations etc) are in same folder. All what I need is to compress (zip) this directory and copy to USB flash disk