Solved

Unlocking files

Posted on 1999-01-23
14
370 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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 …
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

762 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

19 Experts available now in Live!

Get 1:1 Help Now