Link to home
Start Free TrialLog in
Avatar of ble
ble

asked on

Error while writing to an inifile

I have an application on a network drive which will write to an inifile on this network drive.
With Win95/Win98 everything works file, but with Win2000 I get the error "Unable to write to inifilename".
Someone got a clue?
Avatar of Wim ten Brink
Wim ten Brink
Flag of Netherlands image

No access rights???
Avatar of mpoots
mpoots

I have had that same message when I copied my project from a CD which made the ini file read only. So my guess is also that it is a matter of user rights.

Marcel
If you can open and edit the file in notepad, you're access rights are cool.  However, as others have said, it does sound like a security issue.

We had this same problem recently when trying to update an INI file under Terminal Server (W2K).  The problem ended up being that the clown who setup Terminal Server forgot to setup the user's home directory.

Stu
He Marcel!
Before writing to the ini file, clear an eventual read-only flag by calling:

  SetFileAttributes(iniFilePath, 0);

Sometimes writing to ini files work better, if you empty any ini cache before AND after writing like this:

  WritePrivateProfileString(nil, nil, nil, iniFilePath);

Apart from those 2 tips, it might be a security/access rights problem like the others already said.

Regards, Madshi.
Avatar of ble

ASKER

It is not a security problem, because the file can be changed using notepad.
Then try my 2 suggestions...
If that does not help, please post your code here.
Avatar of ble

ASKER

I tried

  FileSetAttr('\test.ini',0);

Still got the same problem. Before setting the attribute to 0, I did a FileGetAttr and the attribute value was 32 (archive bit set).

I am using the following code:

var
  ini: tinifile;
begin
  ini := tinifile.create('.\test.ini');
  ini.WriteString('section','key','value');
  ini.free;

I have also tried your way with WritePrivateProfileString:

  writeprivateprofilestring(nil,nil,nil,'.\test.ini');
  writeprivateprofilestring('section','key','value','.\test.ini');
  writeprivateprofilestring(nil,nil,nil,'.\test.ini');

No error ocured, but then nothing was written to the file!
Hmmm... Try giving in the full path instead of this ".\test.ini" logic. Perhaps that works better. Other than that I've not much ideas left. It works fine for me...

Regards, Madshi.
Avatar of ble

ASKER

I tried also the full path, the same problems.

It did also works fine for me as long I was using Win95 or Win98. The problem only occurs with Win2000. When I am writing to a local disk it doesn't give a problem, only when writeing to a network disk.
ble,

Is there any reason you need to use an inifile anyway?  Can't you use the registry?  After all, the registry was created to replace inifiles.

Stu
Avatar of ble

ASKER

The reason I am using inifiles is that users can log in on every computer and want to use their settings on that computer. By writing into the registry the settings are stored only on one workstation.
The following code worked perfectly on my XP client, which was connected to a win2000 server:

  WritePrivateProfileString('testApp', 'testKey', 'value', '\\mts-s-server\pool\test.ini');

Regards, Madshi.
OK.  That makes sense.  Can you load the contents of the ini file into a TMemo or TStringList?

Stu
Avatar of ble

ASKER

Also giving the URL gives the same error.
Avatar of ble

ASKER

Yes, I can load the contents of the inifile into a TMemo.
Avatar of ble

ASKER

I have the following extra information: When I get the error for GetlastError after calling the WritePrivateProfileString it has the error code 33.  In Win32.hlp I found that this is ROR_LOCK_VIOLATION. But what does that means?
33 = The process can't access the specified file, because another process has locked a part of that file.
Avatar of ble

ASKER

But what process can this be? I am sure no one else is using the same inifile.
Perhaps you should try a totally new project, which does nothing but do one WritePrivateProfileString call. Does that also fail?

Regards, Madshi.
Madshi,

>33 = The process can't access the specified file,
>because another process has locked a part of that
>file.

If that's the case, why is it that the memo has no problems gaining read rights to the file.

ble.  If you can open the inifile in a memo, try saving it as well.  Don't modify it, just Lines.SaveToFile(x).  If that works, then I'm stumped.

Stu
Avatar of ble

ASKER

Madshi,
I did the previous tests in a new test progam with only the inifile writing in it.

Stuart,
It is indeed possible to save the data in the TMemo using SaveToFile.
Also changed data is stored correct.
ASKER CERTIFIED SOLUTION
Avatar of Madshi
Madshi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ble

ASKER

I found the problem. I used Novell Client for Windows version 4.83.
I have gone back to 4.81 and everything is working fine now.
Thank you all for thinking with me.
ble:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
Avatar of ble

ASKER

No one had the solution, I just found it myself (see comment on 4/3/2002)
Why not thank someone who contributed the most... ble...