Go Premium for a chance to win a PS4. Enter to Win

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

Unlocking files

I am writing software which analyses the systems modem log file. One of the features in my software is an optimization routine which compacts the modem log file by removing unnecessary entries. The problem is that sometimes the system seems to keep the file locked well after the dial-up networking session is closed and prevents other programs including mine from accessing or writing to this file.

How can I get around this. Can I force a file to be unlocked which was locked by another application? Is it that the file buffers need flushing and if so how can I do this?
0
bgrove
Asked:
bgrove
1 Solution
 
Shyam121498Commented:
Check Whether the file is getting closed after the session is closed
0
 
AnswerTheManCommented:
i don't think it's the system.
more likeky it's your app. running in debug mode without closing the file.
0
 
bgroveAuthor Commented:
Shyam

Don't post stupid trivial responses without understanding the question.
0
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.

 
bgroveAuthor Commented:
AnswerTheMan

My app has nothing to do with it. This happens intermitantly and it sometimes prevents my app from opening the file when it starts. I am not a fool or a complete novice. This software has already sold more than a hundred copies world wide in a very short period of time. I am looking for advice from someone who knows what they are doing..... not silly comments.

Http://www.home.aone.net.au/tol
0
 
rmichelsCommented:
I was just searching the microsoft help, and could not find an example, but isn't there a function to flush/commit the disk cache.  When you identify a locked file, you could go into a loop and flush the cache, wait, then try again

0
 
covingtonCommented:
Would finding and killing the process that has the file locked be an acceptable solution? Or do you need to use a less intrusive method?

0
 
bgroveAuthor Commented:
Yes that would be acceptable since the dial-up session has been closed. How would one go about searching for processes initiated by other apps or the system itself which have a specific file open?
0
 
rmichelsCommented:
I think the best you could do is get a list of processes, and then searching for the correct name, terminate it (assuming you know the name of the process).

But....killing a processes before it's complete is not the best thing to do..you may cause other problems..since the application just dies and does not fully close.  I would not kill a process just to clean up the file list...and..if the file is locked for sometime after you exit the modem program, then the system is probably being slow about cleaning up the file?
0
 
anzenCommented:
There should be a file handle monitor on the Systems Internals WEB site (http://www.sysinternals.com), I don't remember if this program has an accompanying source but it could be a good starting point to find what is going on with the log file...


0
 
bgroveAuthor Commented:
OK....as I suspected the process which is leaving the file open is the Windows TAPISVR. The real question now is:

HOW EXACTLY DOES ONE CLOSE A FILE WHICH IS OCCASIONALLY LEFT OPEN BY TAPISVR OR ANY OTHER PROCESS FOR THAT MATTER??

If you can answer this properly, you are indeed worthy of praise!
0
 
bgroveAuthor Commented:
Adjusted points to 115
0
 
rondeaujCommented:
 You could take ownership of the file and that would force the operating system to unlock the file.  Just dont forget to release ownership before you finish your task.
0
 
bgroveAuthor Commented:
How? I there an API call to do this? Is there a way to retrieve a file handle?........Code
0
 
MirkwoodCommented:

Here is a sample

Type Record   ' Define user-defined type.
   ID As Integer
   Name As String * 20
End Type

Dim MyRecord As Record, RecordNumber   ' Declare variables.
' Open sample file for random access.
Open "TESTFILE" For Random Shared As #1 Len = Len(MyRecord)
RecordNumber = 4   ' Define record number.
Lock #1, RecordNumber   ' Lock record.
Get #1, RecordNumber, MyRecord   ' Read record.
MyRecord.ID = 234   ' Modify record.
MyRecord.Name = "John Smith"
Put #1, RecordNumber, MyRecord   ' Write modified record.
Unlock #1, RecordNumber   ' Unlock current record.
Close #1   ' Close file.


0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now