Where to save a machine-dependent (not user) ini file in windows

My application currently stores settings in an INI file under the current user profile ( C:\Documents and Settings\<CurrentUser>\Application Data\MyApplication\MySettings.iniunder WinXP). But I realized that some of these parameters are unique to the machine, and not to the user, and therefore want (in fact) to save them in one place for all users.

Is there a folder in Windows XP (and higher) where I can store user settings?

NOTE. I do not want to store them in the same folder as my application, and I do not want to store them in the registry.

I noticed that there is a folder "All Users" in the section "C: \ Documents and Settings \"? Should I store there?

Reward Points: I’m more likely to give an answer to someone who can tell me how to get this path back from Windows to Delphi 7.

+5
source share
2 answers

For XP, Windows provides SHGetFolderPath () to get a known location. The CSIDL you are looking for CSIDL_COMMON_APPDATAis described as:

, . "C:\Documents and Settings\All Users\Application Data". , . , , CSIDL_COMMON_APPDATA. , .

Vista SHGetKnownFolderPath(), SHGetFolderPath() - . Vista, FOLDERID_ProgramData CSIDL_COMMON_APPDATA.

, , .

, ( , Delphi):

function ShGetKnownFolderPath (
    const rfid:   TGUID;
    dwFlags:      DWord;
    hToken:       THandle;
    out ppszPath: PWideChar): HResult;
var
    Shell: HModule;
    Fn: TShGetKnownFolderPath;
begin
    Shell := LoadLibrary ('shell32.dll');
    Win32Check(Shell <> 0);
    try
        @Fn := GetProcAddress (Shell, 'SHGetKnownFolderPath');
        Win32Check (Assigned (Fn));
        Result := Fn (rfid, dwFlags, hToken, ppszPath);
    finally
        FreeLibrary (Shell);
    end;
end;

 

function GetKnownFolderPath (
    const rfid: TGUID;
    dwFlags:    DWord;
    hToken:     THandle): WideString;
var
    buffer: PWideChar;
    ret: HResult;
begin
    ret :=ShGetKnownFolderPath (rfid, dwFlags, hToken, buffer);
    OleCheck (ret);
    try
        Result := buffer;
    finally
        CoTaskMemFree (buffer);
    end;
end;

CSIDL_* FOLDERID_*. , , , "C:\Documents and Settings\<CurrentUser>\Application Data\". , Windows , , .

+12

JEDI Code Library .

JclShell.pas GetSpecialFolderLocation()

YourDataFolder := GetSpecialFolderLocation(CSIDL_COMMON_APPDATA);

, , Windows, API Windows.

+6

All Articles