Take a look here
http://www.pinvoke.net/default.aspx/netapi32/NetFileEnum.html[
^]
Also this could help (source CP)
class Program
{
static void Main(string[] args)
{
const int MAX_PREFERRED_LENGTH = -1;
int dwReadEntries;
int dwTotalEntries;
IntPtr pBuffer = IntPtr.Zero;
FILE_INFO_3 pCurrent = new FILE_INFO_3();
int dwStatus = NetFileEnum(null, null, null, 3, ref pBuffer,
MAX_PREFERRED_LENGTH, out dwReadEntries, out dwTotalEntries, IntPtr.Zero);
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(" num_locks={0}", pCurrent.fi3_num_locks);
Console.WriteLine(" pathname={0}", pCurrent.fi3_pathname);
Console.WriteLine(" permission={0}", pCurrent.fi3_permission);
Console.WriteLine(" username={0}", pCurrent.fi3_username);
}
NetApiBufferFree(pBuffer);
}
}
[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)]
struct FILE_INFO_3
{
public int fi3_id;
public int fi3_permission;
public int fi3_num_locks;
[MarshalAs(UnmanagedType.LPWStr)]
public string fi3_pathname;
[MarshalAs(UnmanagedType.LPWStr)]
public string fi3_username;
}
}
Hope this helps
Cheers!