Using NetFileEnum to determine which files are open on server
Find out who is currently using which file on the server. I am using Windows NETFILEENUM CALL. The structure that i have used in this example is only for WIN NT/2000. If your are going to use WIN95/WIN98/ME grab the structure from msdn file_info_50. Please vote!!!!!
AI
AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Source Code
Private Function GetPointerToByteStringW(ByVal dwData As Long) As String Dim tmp() As Byte Dim tmplen As Long If dwData <> 0 Then tmplen = lstrlenW(dwData) * 2 If tmplen <> 0 Then ReDim tmp(0 To (tmplen - 1)) As Byte CopyMemory tmp(0), ByVal dwData, tmplen GetPointerToByteStringW = tmp End If End If End Function Private Sub Form_Load() Dim bufptr As Long Dim dwServer As Long Dim dwEntriesread As Long Dim dwTotalentries As Long Dim dwResumehandle As Long Dim success As Long Dim nStructSize As Long Dim cnt As Long Dim usrname As String Dim bServer As String Dim fi3 As FILE_INFO_3 bServer = "\\" & ComputerName & vbNullString dwServer = StrPtr(bServer) success = NetFileEnum(dwServer, 0&, 0&, 3,bufptr,MAX_PREFERRED_LENGTH, dwEntriesread,dwTotalentries,dwResumehandle) If success = NERR_SUCCESS And success <> ERROR_MORE_DATA Then nStructSize = LenB(fi3) For cnt = 0 To dwEntriesread - 1 CopyMemory fi3, ByVal bufptr + (nStructSize * cnt), nStructSize usrname = GetPointerToByteStringW(fi3.fi3_username) If Len(usrname) > 0 Then Print usrname & vbTab & fi3.fi3_permissions & vbTab & fi3.fi3_num_locks & vbTab & GetPointerToByteStringW(fi3.fi3_Pathname) End If Next End If Call NetApiBufferFree(bufptr) End Sub
Original Comments (3)
Recovered from Wayback Machine