Solved

Unlocking files

Posted on 1999-01-23
14
372 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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

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
 
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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB6 / DAO 3.6 / run time error: Couldn't find installable ISAM 7 94
Copy a row 12 62
using web browser with BING 40 122
Recommendation vb6 to vb.net or others 14 150
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

803 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