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?
With Win95/Win98 everything works file, but with Win2000 I get the error "Unable to write to inifilename".
Someone got a clue?
No access rights???
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
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
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(iniFileP ath, 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.
SetFileAttributes(iniFileP
Sometimes writing to ini files work better, if you empty any ini cache before AND after writing like this:
WritePrivateProfileString(
Apart from those 2 tips, it might be a security/access rights problem like the others already said.
Regards, Madshi.
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.
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.in i');
ini.WriteString('section', 'key','val ue');
ini.free;
I have also tried your way with WritePrivateProfileString:
writeprivateprofilestring( nil,nil,ni l,'.\test. ini');
writeprivateprofilestring( 'section', 'key','val ue','.\tes t.ini');
writeprivateprofilestring( nil,nil,ni l,'.\test. ini');
No error ocured, but then nothing was written to the file!
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.in
ini.WriteString('section',
ini.free;
I have also tried your way with WritePrivateProfileString:
writeprivateprofilestring(
writeprivateprofilestring(
writeprivateprofilestring(
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.
Regards, Madshi.
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.
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
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
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.
WritePrivateProfileString(
Regards, Madshi.
OK. That makes sense. Can you load the contents of the ini file into a TMemo or TStringList?
Stu
Stu
ASKER
Also giving the URL gives the same error.
ASKER
Yes, I can load the contents of the inifile into a TMemo.
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.
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.
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
>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
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
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.
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...