Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools


_lOpen, _lClose

Click here to copy the following block
'Determine whether a file is already open or not
Private Declare Function lOpen Lib "kernel32" Alias "_lopen" (ByVal lpPathName As String, ByVal iReadWrite As Long) As Long
Private Declare Function lClose Lib "kernel32" Alias "_lClose " (ByVal hFile As Long) As Long

Private Function IsFileOpened(FileName As String) As Boolean
  Dim hFile As Long
  Dim lastErr As Long
  ' Initialize file handle and error variable.
  hFile = -1
  lastErr = 0
  ' Open for for read and exclusive sharing.
  hFile = lOpen(FileName, &H10)
  ' If we couldn't open the file, get the last error.
  If hFile = -1 Then
    lastErr = Err.LastDllError
    'ShowAPIErr lastErr
  Else
    ' Make sure we close the file on success.
    lClose (hFile)
  End If
  ' Check for sharing violation error.
  IsFileOpened = (hFile = -1) And (lastErr = 32)
End Function

Private Sub Form_Load()
On Error GoTo errhandler
Dim Handle As Long
Dim FileName As String

  'FileName = "c:\test.xls"
  FileName = "c:\autoexec.bat"
  
  Handle = FreeFile
  'Open FileName For Input As #Handle
  
  If IsFileOpened(FileName) Then
    MsgBox FileName & " is Opened by someone"
  Else
    MsgBox FileName & " is closed"
  End If
  
  'Close #Handle
  
  Exit Sub
errhandler:
  MsgBox Err.Description
End Sub


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.