File in use Vb

just found nice code in internet, and i use it in one of my project. works great!
it will return the last user that open the file

Function LastUser(strPath As String) As String

‘// Code by Helen from http://www.xtremevbtalk.com/index.php?s=

‘// This routine gets the Username of the File In Use

‘// Credit goes to Helen for code & Mike for the idea

‘// Amendment 25th June 2004

‘// : Name changes will show old setting

‘// : you need to get the Len of the Name store just before

‘// : the double Padded nullstrings

Dim text As String

Dim strFlag1 As String, strflag2 As String

Dim i As Integer, j As Integer

Dim hdlFile As Long

Dim lNameLen As Byte

strFlag1 = Chr(0) & Chr(0)

strflag2 = Chr(32) & Chr(32)

hdlFile = FreeFile

Open strPath For Binary As #hdlFile

text = Space(LOF(hdlFile))

Get 1, , text

Close #hdlFile

j = InStr(1, text, strflag2)

i = InStrRev(text, strFlag1, j) + Len(strFlag1)

lNameLen = Asc(Mid(text, i – 3, 1))

LastUser = Mid(text, i, lNameLen)

End Function

This entry was posted in vb and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>