[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 903
  • Last Modified:

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?
0
ble
Asked:
ble
  • 11
  • 8
  • 4
  • +4
1 Solution
 
Wim ten BrinkCommented:
No access rights???
0
 
mpootsCommented:
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
0
 
Stuart_JohnsonCommented:
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
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
JaccoCommented:
He Marcel!
0
 
MadshiCommented:
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.
0
 
bleAuthor Commented:
It is not a security problem, because the file can be changed using notepad.
0
 
MadshiCommented:
Then try my 2 suggestions...
0
 
MadshiCommented:
If that does not help, please post your code here.
0
 
bleAuthor Commented:
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!
0
 
MadshiCommented:
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.
0
 
bleAuthor Commented:
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.
0
 
Stuart_JohnsonCommented:
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
0
 
bleAuthor Commented:
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.
0
 
MadshiCommented:
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.
0
 
Stuart_JohnsonCommented:
OK.  That makes sense.  Can you load the contents of the ini file into a TMemo or TStringList?

Stu
0
 
bleAuthor Commented:
Also giving the URL gives the same error.
0
 
bleAuthor Commented:
Yes, I can load the contents of the inifile into a TMemo.
0
 
bleAuthor Commented:
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?
0
 
MadshiCommented:
33 = The process can't access the specified file, because another process has locked a part of that file.
0
 
bleAuthor Commented:
But what process can this be? I am sure no one else is using the same inifile.
0
 
MadshiCommented:
Perhaps you should try a totally new project, which does nothing but do one WritePrivateProfileString call. Does that also fail?

Regards, Madshi.
0
 
Stuart_JohnsonCommented:
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
0
 
bleAuthor Commented:
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.
0
 
MadshiCommented:
Okay, maybe the access right you have is a strange one: It allows reading and creating, but not changing. That would explain all the effects (notebook does not change, it completely rewrites the file, so does TMemo.SaveToFile). Such strange access rights are possible, though unprobable...

Try these calls, do they all success or does one of them fail?

TFileStream.Create('\\server\share\test.ini', fmOpenRead);
TFileStream.Create('\\server\share\test.ini', fmCreate);
TFileStream.Create('\\server\share\test.ini', fmOpenWrite);
TFileStream.Create('\\server\share\test.ini', fmOpenReadWrite);

One solution would be to copy the ini file to your local harddisk, then modify it there and copy it back. Ugly, but should work...

Regards, Madshi.
0
 
bleAuthor Commented:
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.
0
 
CleanupPingCommented:
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.
0
 
bleAuthor Commented:
No one had the solution, I just found it myself (see comment on 4/3/2002)
0
 
JaccoCommented:
Why not thank someone who contributed the most... ble...
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 11
  • 8
  • 4
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now