[DllImport("Netapi32.dll")]
extern static int NetUserEnum([MarshalAs(UnmanagedType.LPWStr)]
string servername,
int level,
int filter,
out IntPtr bufptr,
int prefmaxlen,
out int entriesread,
out int totalentries,
out int resume_handle);
Public Declare Function NetUserEnum Lib "Netapi32.dll" ( _
<MarshalAs(UnmanagedType.LPWStr)> ByVal servername As String, _
ByVal level As Integer, _
ByVal filter As Integer, _
ByRef bufptr As IntPtr, _
ByVal prefmaxlen As Integer, _
ByRef entriesread As Integer, _
ByRef totalentries As Integer, _
ByRef resume_handle As Integer) As Integer
// Passing -1 as prefmaxlen makes the system allocate the buffer.
// LMCONS.h
const int MAX_PREFERRED_LENGTH = -1;
// You'll need these for the return values
// LMERR.h
const int NERR_Success = 0; /* Success */
const int NERR_BASE = 2100;
const int NERR_InvalidComputer = (NERR_BASE+251); /* This computer name is invalid. */
// WINERROR.h
const int ERROR_ACCESS_DENIED = 5;
const int ERROR_MORE_DATA = 234;
None.
Please add some!
ArrayList users = new ArrayList();
int EntriesRead;
int TotalEntries;
int Resume;
IntPtr bufPtr;
NetUserEnum(server, 0, 2, out bufPtr, -1, out EntriesRead, out TotalEntries, out Resume);
if(EntriesRead> 0)
{
USER_INFO_0[] Users = new USER_INFO_0[EntriesRead];
IntPtr iter = bufPtr;
for(int i=0; i < EntriesRead; i++)
{
Users[i] = (USER_INFO_0)Marshal.PtrToStructure(iter, typeof(USER_INFO_0));
iter = (IntPtr)((int)iter + Marshal.SizeOf(typeof(USER_INFO_0)));
users.Add(Users[i].Username);
}
NetApiBufferFree(bufPtr);
}
Do you know one? Please contribute it!