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.
NetUserGetLocalGroups (netapi32)
.
C# Signature:
public extern static int NetUserGetLocalGroups([MarshalAs(UnmanagedType.LPWStr)] string servername,
[MarshalAs(UnmanagedType.LPWStr)] string username,
int level,
int flags,
out IntPtr bufptr,
int prefmaxlen,
out int entriesread,
out int totalentries);
[DllImport("Netapi32.dll", SetLastError=true)]
public static extern int NetApiBufferFree(IntPtr Buffer);
VB Signature:
Declare Function NetUserGetLocalGroups Lib "netapi32.dll" (TODO) As TODO
User-Defined Types:
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
public struct LOCALGROUP_USERS_INFO_0
{
public string groupname;
}
Alternative Managed API:
Do you know one? Please contribute it!
Notes:
None.
Tips & Tricks:
Please add some!
Sample Code:
//Exapmle code to place in class file or dll.
public static ArrayList GetUserLocalGroup(string ServerName,string Username, int Flags)
{
ArrayList myList = new ArrayList();
int EntriesRead;
int TotalEntries;
IntPtr bufPtr;
val = NetUserGetLocalGroups(ServerName,Username,0,Flags,out bufPtr,1024,out EntriesRead, out TotalEntries);
if(val==0)
{
_errormsg="Successful";
}
else
{
_errormsg="Username or computer not found";
}
if(Flags>1)
_errormsg="Flags can only be 0 or 1";
if(EntriesRead> 0)
{
LOCALGROUP_USERS_INFO_0[] RetGroups = new LOCALGROUP_USERS_INFO_0[EntriesRead];
IntPtr iter = bufPtr;
for(int i=0; i < EntriesRead; i++)
{
RetGroups[i] = (LOCALGROUP_USERS_INFO_0)Marshal.PtrToStructure(iter, typeof(LOCALGROUP_USERS_INFO_0));
iter = (IntPtr)((int)iter + Marshal.SizeOf(typeof(LOCALGROUP_USERS_INFO_0)));
myList.Add(RetGroups[i].groupname);
}
NetApiBufferFree(bufPtr);
}
return myList;
}
//Expample code for calling application
ArrayList RetGroups = new ArrayList();
RetGroups =DsDomain.GetUserLocalGroup(null,"administrator",0);
//DsDomain.GetUserLocalGroup();
foreach(string str in RetGroups)
{
Console.WriteLine(str);
}
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).