Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Unlocking files

Posted on 1999-01-23
14
Medium Priority
?
378 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

722 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