I am using NetFileEnum like this but the pathname doesn't actually give
me the filename - how do I get the actual filename?
:
[DllImport("netapi32.dll", SetLastError=true, CharSet=CharSet.Unicode)]
static extern int NetFileEnum(
string servername,
string basepath,
string username,
int level,
ref IntPtr bufptr,
int prefmaxlen,
out int entriesread,
out int totalentries,
IntPtr resume_handle
);
[DllImport("Netapi32.dll", SetLastError=true)]
static extern int NetApiBufferFree(IntPtr Buffer);
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=4)]
struct FILE_INFO_3
{
public int fi3_id;
public int fi3_permission;
public int fi3_num_locks;
public string fi3_pathname;
public string fi3_username;
}
int dwStatus = NetFileEnum(servername, null, null, 3, ref pBuffer, -1,
out dwReadEntries, out dwTotalEntries, IntPtr.Zero );
int dwReadEntries;
int dwTotalEntries;
IntPtr pBuffer = IntPtr.Zero ;
FILE_INFO_3 pCurrent = new FILE_INFO_3();
if (dwStatus == 0)
{
for (int dwIndex=0; dwIndex < dwReadEntries; dwIndex++)
{
IntPtr iPtr = new IntPtr(pBuffer.ToInt32() + (dwIndex *
Marshal.SizeOf(pCurrent)));
pCurrent = (FILE_INFO_3) Marshal.PtrToStructure(iPtr,
typeof(FILE_INFO_3));
Console.WriteLine("dwIndex={0}", dwIndex);
Console.WriteLine(" id={0}", pCurrent.fi3_id );
Console.WriteLine(" pathname={0}", pCurrent.fi3_pathname);
Console.WriteLine(" username={0}", pCurrent.fi3_username);
}
NetApiBufferFree(pBuffer);
}
thanks
Phil