'CloseFile' dont really close the file

When using the CloseFile command, the file is still locked/open.

Se code below..

Procedure ..............
 DataFilll : Textfile;
 TextString : string;
 assignfile(DataFilll, OpenDialog1.filename);
 readln(DataFilll, Textstring);

After this i may want to delete the file, but access is permitted.
The file is released after the application is closed.

I'm runnig Win95 on NT network. The file is located on the server.
Who is Participating?
BlackManConnect With a Mentor Commented:
Okay, try this one (you must change it on the server)


CachedOpenLimit     REG_DWORD     0x0 - 0xFFFFFFFF

Default: 0x5

Specifies the maximum number of file handles the Server service is permitted to cache. File handle caching, a Server service optimization, maintains open file handles even when a client closes the file. This keeps the file available for subsequent access and eliminates repeated open and close operations. To disable file handle caching, set the value of this entry to 0.

If the value of this entry is at least 1, then when a client closes a file on which the Server service owns an opportunistic lock (oplock), the Server returns the Close SMB response indicating that the file has been closed, but it actually keeps the file open. (The Server removes the remote file control block (RFCB), but maintains the local file control block (LFCB) and does not issue the local NtClose() request.)


Windows NT does not add this value to the Registry. You can add it by editing the Registry or by using a program that edits the Registry.
      This value entry is supported only by Windows NT 3.5 and later.

You may find that the file has been opened somewhere else in your app and it is only released with the app is closed.

There are also known problems with NT servers not always permitting a file to be deleted even when nothing has it open.



PeterLarsenAuthor Commented:
Hi rwilson, and thanks for your reply.

The application open about 20 files on start - read them and close them again.

If i leave the program open for an hour or 2, some of the files are still open. After 10 min. 10 files (or so) are open - after 20 min. 5 files (or less) may still be open.

The 'Open Resources on SERVER_NAME'  vindow on the server, show files-open status for all users on the network. It use the server to see 'open-files status' for my application.

Peter Larsen
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Are you running the program from a client with the files on a NT server? If so, that is probably the cause. There are some registry entries that you can fiddle with to change the behaviour, let me know if you want me to dig them out for you...
PeterLarsenAuthor Commented:
Hi BlackMan,

Very intresting, but i don't understand why this i neccesary (necesary ?) Is it the FileClose command, that makes the problem ??

And finally, How do i accept or reject an answar from an expert ??
Last thing first.. When an Expert has given you an answer, there is an option to accept or reject it when you read it...
The reason that this is happening, is that NT Server is optimized for, guess what, server operations :-) Because of that, when you close the file, NTS say to itself "Hmm, he, or someone else, might want to open that file again soon, I'll just tell him I closed it but I'll keep open for a while, then I might save myself some time when someone wants to open it again"
What you can tweak in the registry, is the amount of time NT holds the file open before it actually closes it...
PeterLarsenAuthor Commented:
Hi BlackMan,

First thing first :)

When i read your message - the only options i get is :
Increase points to:  
Edit question...
Delete question...
Have a comment to add?  

Do i look in the wrong place ??

But, i would like to accept your answar.
Please return the name of the registry key AND how i accept/pay you for the answar.

Peter Larsen
First thing first them :-)
That is because the question is not answered yet, both Raymond and I have only given you comments, because we don't have an valid answer...
I will try to find the key but it won't be before tomorrow, sorry..
PeterLarsenAuthor Commented:
Tomorrow ? Tomorrow is fine. So you don't think you have a valid answer ? It looks valid for me :)
Well, you haven't tried it yet :-)
Is'nt there a CloseAll or Close(0) that closes all files that an app has open. Maybe this will enable you to debug ?

Oops, Peter, I just realised that I've totally forgot this question.. I've put it on my ToDo-list... Sorry!
PeterLarsenAuthor Commented:

Well, we haven't tried it yet, but your answer explaines why the server leave files open for some time after a close command.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.