Solved

Check file lock

Posted on 2003-11-09
3
316 Views
Last Modified: 2010-05-01
How could one check to see if a file is in use by another user. Example: I need to delete a file but before I do, check to see if it’s in use.

Is this possible?

   - Marc
0
Comment
Question by:MarcGraff
3 Comments
 
LVL 24

Accepted Solution

by:
R_Rajesh earned 250 total points
Comment Utility
try this,

Private Sub Form_Load()
Dim strFileName As String
' Full path and name of file.
strFileName = "C:\calc.exe"
' Call function to test file lock.
If Not FileLocked(strFileName) Then
' If the function returns False, file in not in use
MsgBox "not open, can delete it"
Else
MsgBox "file is open, cant delete it"
End If
End Sub

Function FileLocked(strFileName As String) As Boolean
On Error Resume Next
' If the file is already opened by another process,
' and the specified type of access is not allowed,
' the Open operation fails and an error occurs.
Open strFileName For Binary Access Read Write Lock Read Write As #1
Close #1
' If an error occurs, the document is currently open.
If Err.Number <> 0 Then
' Display the error number and description.
'MsgBox "Error #" & Str(Err.Number) & " - " & Err.Description
FileLocked = True
Err.Clear
End If
End Function
0
 
LVL 9

Expert Comment

by:Valliappan AN
Comment Utility
0
 
LVL 1

Author Comment

by:MarcGraff
Comment Utility
Thank you so much!

   - Marc
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…

771 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

10 Experts available now in Live!

Get 1:1 Help Now