NetFileEnum Result



Hi All,

I am trying to find out all the Open Files on our Server. I
am using NetFileEnum API to do that.

This is the code, I am using to get all the files. it is returing
something that is all numbers.
For example: Path should like something like "c:\SBC\ytdret.xml" but it
is returning 45678954. I don't know how to see the real path. If
somebody help me then I will appreciate them. I tried changing
fi3_pathname to string but then I see b;ank string in PathName.

Imports System
Imports System.Runtime.InteropServices

Public Class Form1

Inherits System.Windows.Forms.Form

Declare Function NetFileEnum Lib "netapi32.dll" ( _
ByVal servername As String, _
ByVal basepath As String, _
ByVal username As String, _
ByVal level As Integer, _
ByRef bufptr As IntPtr, _
ByVal prefmaxlen As Integer, _
ByRef entriesread As Integer, _
ByRef totalentries As Integer, _
ByVal resume_handle As IntPtr) As Integer

Private Structure FILE_INFO_3
Dim fi3_id As Long
Dim fi3_permissions As Long
Dim fi3_num_locks As Long
Dim fi3_pathname As Long
Dim fi3_username As Long
End Structure


#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(40, 16)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(128, 32)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Const MAX_PREFERRED_LENGTH As Integer = -1
Dim dwIndex, dwStatus, dwReadEntries, dwTotalEntries As Integer

Dim pCurrent As FILE_INFO_3
Dim iPtr, pBuffer As IntPtr

dwStatus = NetFileEnum(Nothing, Nothing, Nothing, 3, pBuffer,
MAX_PREFERRED_LENGTH, dwReadEntries, dwTotalEntries, Nothing)
If dwStatus = 0 Then
For dwIndex = 0 To dwReadEntries - 1

iPtr = New IntPtr(pBuffer.ToInt32 + (dwIndex *
Len(pCurrent)))

pCurrent = CType(Marshal.PtrToStructure(iPtr,
GetType(FILE_INFO_3)), FILE_INFO_3)
MsgBox(pCurrent.fi3_id)
Debug.WriteLine("dwIndex=" & dwIndex)
Debug.WriteLine(" id: " & pCurrent.fi3_id)
Debug.WriteLine(" num_locks: " &
pCurrent.fi3_num_locks)
Debug.WriteLine(" pathname: " &
pCurrent.fi3_pathname)
Debug.WriteLine(" permission: " &
pCurrent.fi3_permissions)
Debug.WriteLine(" username: " &
pCurrent.fi3_username)
Next
End If

End Sub
End Class

Thanks
Nikki

.