Solved

Unlocking files

Posted on 1999-01-23
14
371 Views
Last Modified: 2010-05-03
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
Comment
Question by:bgrove
14 Comments
 
LVL 1

Expert Comment

by:Shyam121498
ID: 1470252
Check Whether the file is getting closed after the session is closed
0
 
LVL 5

Expert Comment

by:AnswerTheMan
ID: 1470253
i don't think it's the system.
more likeky it's your app. running in debug mode without closing the file.
0
 

Author Comment

by:bgrove
ID: 1470254
Shyam

Don't post stupid trivial responses without understanding the question.
0
 

Author Comment

by:bgrove
ID: 1470255
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
 
LVL 3

Expert Comment

by:rmichels
ID: 1470256
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
 
LVL 3

Expert Comment

by:covington
ID: 1470257
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
 

Author Comment

by:bgrove
ID: 1470258
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Expert Comment

by:rmichels
ID: 1470259
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
 
LVL 4

Expert Comment

by:anzen
ID: 1470260
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
 

Author Comment

by:bgrove
ID: 1470261
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
 

Author Comment

by:bgrove
ID: 1470262
Adjusted points to 115
0
 
LVL 1

Expert Comment

by:rondeauj
ID: 1470263
 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
 

Author Comment

by:bgrove
ID: 1470264
How? I there an API call to do this? Is there a way to retrieve a file handle?........Code
0
 
LVL 13

Accepted Solution

by:
Mirkwood earned 120 total points
ID: 1470265

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBA: Add rows to listbox based on criteria 7 73
Windows 10 start screen issues 9 51
Copy a row 12 57
VB6 - Convert HH:MM into Decimal 8 51
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

919 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

13 Experts available now in Live!

Get 1:1 Help Now