Where does the INI file get put

Hi all

I am using
Ini := TIniFile.Create(ChangeFileExt(Application.ExeName, ‘.INI’));

But for the life of me I can not find the INI configuration file that ought to have been created

I have looked in the project folder and the Win32 project folder but can not find

Can some one give me some guidance on this

Grant

Default is c:\windows, it has baffled a lot of people :wink:

You would typically need to suffix it with your desired path to control where it gets created.

Alex

Perhaps change it to

Ini := TIniFile.Create(ChangeFileExt(ParamStr(0), ‘.INI’));

ParamStr(0) includes both the exe name and the path.

1 Like

Hi Grant

Have you added/changed any properties/entries in Ini.

It may not actually create the file until ini has been worked on.

In any case I would expect the file to be in the folder along side the
exe file.

Regards
Graeme Keast

Actually it will be created in the exe path because Application.ExeName contains the full path to the exe

But it won’t do that until you use one of the TIniFile write methods to create an entry.

John

… except for ‘modern’ windows with UAC on, in which case it will probably be in C:\Users*YourUsedID*\AppData\Local\VirtualStore and below

1 Like

Hi Alexander,

Yea looked there but to no avail

anyway got around it with

Ini := TIniFile.Create(ExtractFilePath(Application.ExeName) + Configuration_File_Name);

Worked a treat

Sometimes, Windows would redirected it to under user profile, to “\AppData\Roaming\Microsoft\Windows” – anything there, for the user account executing that process?

Alex

John_Van_De_Giessen
he said it right for a single user
when the application starts up so GetCurrentDirectory into a separate string
Use the string to save and load the *.INI file of yours
if you have many users, so you need current user directory and make a sub folder for the *.INI file

you can put many sperate users in your many named *.INI files in by the application’s GetCurrentDirectory windows has gone crazy with options
its about piratical stuff

Be wary of what Windows User Account control does - you write to Application.Exename but if this is under C:\Program Files then it is written to some obscure directory perhaps accessible to your code via the directory link you listed while the code runs but really stored in an obscure path such as listed by one of the other respondents. Windows say to put it under places like C:\ProgramData but they restrict access there too. Worse still, when you install your software using an installer, the installer privelages can substitute for your privelages and result in software that works for you but no one else.

I store settings (as xml files) under
C:\Users{Username}\AppData\Roaming{CompanyName}{ProgramName}

That works well, is per user and is a known place no matter where the exe is installed.

1 Like

Grant,

Yea it usually does wired stuff with INI placement.
I think Delphi (in the past, maybe now) attempts to create it in the Programs directory, which has NO write access generally.

Do windows redirects it to a virtual "Programs directory” directory but actually in "C:\users"

Anyway, I discovered that the dull path is best to be put in the “.ini” file creation.

Below is the code I utilise (for many years since Windows stopped allowing write to the Programs directory). It gets a directory in “App Data” and I place it in my own sub-directory (“HakaSoft”)

FUNCTION GetLocalAppData:STRING;
BEGIN
SetLength(Result,MAX_PATH);
SHGetSpecialFolderPath(0,PChar(Result),$001C,false);
SetLength(Result,StrLen(PChar(Result)));
IF (Result<>‘’) THEN
BEGIN
Result:= IncludeTrailingBackslash(Result)+'HakaSoft';
// USe your name in replace of HakaSoft above
ForceDirectories(Result);
END
ELSE Result:= IncludeTrailingBackslash(ExtractFilePath(Paramstr(0)));
END;

procedure TMainWin.FormCreate(Sender: TObject);
var NavIni:TIniFile;
begin
// IniFile
NavIni:= TIniFile.Create(GetLocalAppData+‘LOS.ini’);
tt:= NavIni.ReadInteger(‘Window’,‘Top’,-1);
tl:= NavIni.ReadInteger(‘Window’,‘Left’,-1);
tw:= NavIni.ReadInteger(‘Window’,‘Width’,-1);
th:= NavIni.ReadInteger(‘Window’,‘Height’,-1);
NavIni.Free;

UPDATE:

The subdirectory name needs a Backslash.

i.e. Result:= IncludeTrailingBackslash(Result)+'HakaSoft';
not Result:= IncludeTrailingBackslash(Result)+‘HakaSoft’;

As below:

FUNCTION GetLocalAppData:STRING;
BEGIN
SetLength(Result,MAX_PATH);
SHGetSpecialFolderPath(0,PChar(Result),$001C,false);
SetLength(Result,StrLen(PChar(Result)));
IF (Result<>‘’) THEN
BEGIN
Result:= IncludeTrailingBackslash(Result)+'HakaSoft';
ForceDirectories(Result);
END
ELSE Result:= IncludeTrailingBackslash(ExtractFilePath(Paramstr(0)));
END;

Again use your name in replace of 'HakaSoft'

What is up with the “ADUG Forums” with dropping backslashes??

Testing

1 backslash
Result:= IncludeTrailingBackslash(Result)+'HakaSoft';

2 backslashes
Result:= IncludeTrailingBackslash(Result)+‘HakaSoft\’;

3 backslashws
Result:= IncludeTrailingBackslash(Result)+'HakaSoft\';

4 backslashes
Result:= IncludeTrailingBackslash(Result)+‘HakaSoft\\’;

This works in firemonkey (probably VCL too):
LocalPath := System.IOUtils.TPath.Combine(System.IOUtils.TPath.GetPublicPath, ‘YourCompanyName’);
ForceDirectories(LocalPath);
IniFile := TMemIniFile.Create(LocalPath + ‘\MyProgramName.ini’);

The slash thing is because of Markdown.

Some characters need to be escaped.

Well, actually, source code should be marked specially:

procedure LaLaLand
begin
  something := useful * here;
end;

Using the “left angle bracket + slash + right angle bracket” (hint says: Preformatted text) tool button above the message edit, any already selected text will look like the above. :+1:

1 Like
This is a single backslash test \
1 Like

Test successful. You are free to move about the cabin.