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 = 0 xFFFFFFFF,
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 sums es the count
// Elements actually enumerated.
Ref totalentries, // value that sums es the approximate total
// Number of entries that cocould have been
//