internal class Win32API
{
#region Win32 API Interfaces
[DllImport( "netapi32.dll", EntryPoint = "NetApiBufferFree" )]
internal static extern void NetApiBufferFree(IntPtr bufptr);
[DllImport( "netapi32.dll", EntryPoint = "NetLocalGroupGetMembers" )]
internal static extern uint NetLocalGroupGetMembers(
IntPtr ServerName,
IntPtr GrouprName,
uint level,
ref IntPtr siPtr,
uint prefmaxlen,
ref uint entriesread,
ref uint totalentries,
IntPtr resumeHandle);
[DllImport( "netapi32.dll", EntryPoint = "NetLocalGroupEnum" )]
internal static extern uint NetLocalGroupEnum(
IntPtr ServerName,
uint level,
ref IntPtr siPtr,
uint prefmaxlen,
ref uint entriesread,
ref uint totalentries,
IntPtr resumeHandle);
[StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Auto)]
internal struct LOCALGROUP_MEMBERS_INFO_1
{
public IntPtr lgrmi1_sid;
public IntPtr lgrmi1_sidusage;
public IntPtr lgrmi1_name;
}
[StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Auto)]
internal struct LOCALGROUP_INFO_1
{
public IntPtr lpszGroupName;
public IntPtr lpszComment;
}
#endregion
}
private void groupbtn_Click(object sender, System.EventArgs e)
{
//defining values for getting group names
uint level = 1, prefmaxlen = 0xFFFFFFFF,
entriesread = 0, totalentries = 0;
//Values that will receive information.
IntPtr GroupInfoPtr,UserInfoPtr;
GroupInfoPtr = IntPtr.Zero;
UserInfoPtr = IntPtr.Zero;
Win32API.NetLocalGroupEnum(
IntPtr.Zero, //Server name.it must be null
level,//level can be 0 or 1 for groups.
//For more information see LOCALGROUP_INFO_0
//and LOCALGROUP_INFO_1
ref GroupInfoPtr,//Value that will be receive information
prefmaxlen,//maximum length
ref entriesread,//value that receives the count of
//elements actually enumerated.
ref totalentries,//value that receives the approximate total
//number of entries that could have been
//