Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than netapi32, prefix the name with the module name and a period.
NetUserEnum (netapi32)
.
C# Signature:
[DllImport("Netapi32.dll")]
extern static int NetUserEnum([MarshalAs(UnmanagedType.LPWStr)]
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
User-Defined Types:
None.
Notes:
None.
Tips & Tricks:
Please add some!
Sample Code:
public static Hashtable GetUsersListWithNETAPI(string strServerName)
{
//with struct USER_INFO_1
ArrayList users = new ArrayList();
Hashtable userlist=new Hashtable();
int EntriesRead;
int TotalEntries;
int Resume;
IntPtr bufPtr;
string strServer;
if (strServerName.Trim()!="")
{
strServer=@"\\"+strServerName;
}
else
{
strServer=strServerName;
}
try
{
NetUserEnum(strServer, 2, 2, out bufPtr, -1, out EntriesRead, out TotalEntries, out Resume);
if(EntriesRead> 0)
{
USER_INFO_2[] Users = new USER_INFO_2[EntriesRead];
IntPtr iter = bufPtr;
for(int i=0; i < EntriesRead; i++)
{
Users[i] = (USER_INFO_2)Marshal.PtrToStructure(iter, typeof(USER_INFO_2));
iter = (IntPtr)((int)iter + Marshal.SizeOf(typeof(USER_INFO_2)));
The NetUserEnum function provides information about all user accounts on a server.
2/14/2016 8:06:51 AM - -108.168.5.220
An IntPtr is a pointer to a memory location (unmanaged) that adapts to the platform it is running on (64-bit, etc.) UNLIKE a standard int/Integer. You should always use this type for unmanaged calls that require it, even though an int will appear to work on your development machine.
1/13/2008 4:00:13 AM - Damon Carr-72.43.165.29
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).