|
-
Feb 14th, 2003, 11:21 AM
#1
Thread Starter
Hyperactive Member
NetUserGetGroups API
All,
I have a call to the NetUserGetGroups API and can get the first entry in the returned User Groups back.
My question is, how do I iterate through the entire list of user groups??
the code I am using is below:-
Code:
Public Function GetGroups(ByVal UserID As String) As Boolean
Dim GI0 As New GROUP_USERS_INFO_0()
Dim Level As Integer = 0
Dim Server As String = GetPDC() & vbNullChar
Dim i As Integer
Dim lRet As Integer = -1
Dim size As Integer = Marshal.SizeOf(GI0)
Dim lpBuf As IntPtr = Marshal.AllocHGlobal(size)
Dim EntriesRead As Integer
Dim TotalEntries As Integer
UserID = UserID & vbNullChar
Marshal.StructureToPtr(GI0, lpBuf, True)
lRet = NetUserGetGroups(Server, UserID, Level, lpBuf, -1, _
EntriesRead, TotalEntries)
If lRet = NERR_SUCCESS Then
GI0 = CType(Marshal.PtrToStructure(lpBuf, _
GetType(GROUP_USERS_INFO_0)), GROUP_USERS_INFO_0)
For i = 1 To EntriesRead
_myGroupsbox.Items.Add(GI0.grui0_name)
'How do I get the next Group!!!!!????
Next
End If
"I'm Brian and so is my Wife"
-
Sep 13th, 2006, 10:55 AM
#2
New Member
Re: NetUserGetGroups API
Hi,
I've found a sample code in c# using NetUserGetLocalGroups and here is the extract you're looking for :
Code:
groups = new string[totalentries];
Type typeOfStruct = typeof(LOCALGROUP_USERS_INFO_0);
int sizeOfStruct = Marshal.SizeOf(typeOfStruct);
LOCALGROUP_USERS_INFO_0 LGInfo;
IntPtr currentStructPtr;
// parcours du buffer
for (int i = 0; i < totalentries; i++)
{
// définition du pointeur de lecture dans le buffer
currentStructPtr = new IntPtr((int)bufptr + (i * sizeOfStruct));
// récupération de l'instance de LOCALGROUP_USERS_INFO_0
LGInfo = (LOCALGROUP_USERS_INFO_0)Marshal.PtrToStructure(currentStructPtr, typeOfStruct);
groups[i] = LGInfo.groupname;
}
I'm trying to use NetUserGetLocalGroups and NetUserGetGroups with vb net but I always received 2221. I probably have a problem with data type or the I declare the API.
Could tell how you declare the API in your code please ?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|