NetUserGetGroups

LeeSalter

Active member
Joined
Feb 13, 2003
Messages
26
Location
In a House
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)
              [b]  How do I get the next Group!!!!!???? [/b]
            Next
        End If
 
This seems to work:-

Code:
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)

                lpBuf2 = lpBuf.ToInt32
                lpBuf2 = lpBuf2 + Marshal.SizeOf(GI0)

                lpBuf = New IntPtr(lpBuf2)

                GI0 = CType(Marshal.PtrToStructure(lpBuf, _
                    GetType(GROUP_USERS_INFO_0)), GROUP_USERS_INFO_0)

            Next
            Marshal.FreeCoTaskMem(lpBuf)
            Return True
        Else
            Marshal.FreeHGlobal(lpBuf)
            Return False
        End If

Although Im not too sure how Memory efficient this is........comments please!
 

Similar threads

Back
Top