Solved

Error while writing to an inifile

Posted on 2002-03-26
29
781 Views
Last Modified: 2010-05-18
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
Comment
Question by:ble
  • 11
  • 8
  • 4
  • +4
29 Comments
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 6896516
No access rights???
0
 
LVL 1

Expert Comment

by:mpoots
ID: 6897367
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
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 6897784
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
 
LVL 10

Expert Comment

by:Jacco
ID: 6897832
He Marcel!
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6898614
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
 

Author Comment

by:ble
ID: 6898689
It is not a security problem, because the file can be changed using notepad.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6898763
Then try my 2 suggestions...
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6898767
If that does not help, please post your code here.
0
 

Author Comment

by:ble
ID: 6898813
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
 
LVL 20

Expert Comment

by:Madshi
ID: 6898826
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
 

Author Comment

by:ble
ID: 6898834
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
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 6898848
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
 

Author Comment

by:ble
ID: 6898854
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
 
LVL 20

Expert Comment

by:Madshi
ID: 6899038
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 6899113
OK.  That makes sense.  Can you load the contents of the ini file into a TMemo or TStringList?

Stu
0
 

Author Comment

by:ble
ID: 6899126
Also giving the URL gives the same error.
0
 

Author Comment

by:ble
ID: 6899137
Yes, I can load the contents of the inifile into a TMemo.
0
 

Author Comment

by:ble
ID: 6899153
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
 
LVL 20

Expert Comment

by:Madshi
ID: 6899211
33 = The process can't access the specified file, because another process has locked a part of that file.
0
 

Author Comment

by:ble
ID: 6899235
But what process can this be? I am sure no one else is using the same inifile.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6899292
Perhaps you should try a totally new project, which does nothing but do one WritePrivateProfileString call. Does that also fail?

Regards, Madshi.
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 6900465
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
 

Author Comment

by:ble
ID: 6901906
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
 
LVL 20

Accepted Solution

by:
Madshi earned 100 total points
ID: 6901918
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
 

Author Comment

by:ble
ID: 6915306
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
 

Expert Comment

by:CleanupPing
ID: 9343216
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
 

Author Comment

by:ble
ID: 9343380
No one had the solution, I just found it myself (see comment on 4/3/2002)
0
 
LVL 10

Expert Comment

by:Jacco
ID: 9347515
Why not thank someone who contributed the most... ble...
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now