NT user name & user groups 
Author Message
 NT user name & user groups

At present within our organisation we provide access to standard templates
via a customised toolbar in Word.  Due to changes in working practises by
business area we would like to adapt the toolbar to only view certain
templates dependant on NT Group membership.  Is it possible using VB or VBA
to customise the toolbar in such a way that it will automatically show the
appropriate view as determined by the NT access.  For further info we are
running NT 4 SP5 and Office 97.

Paul



Tue, 24 Feb 2004 16:12:26 GMT  
 NT user name & user groups
I don't see why not since it is possible to determine what local/domain
groups a user belongs to by using the Win32API  (Hint: NetUserGetLocalGroups
& NetUserGetGroups - neither is supported under Win9x) or using ADSI.


Quote:
> At present within our organisation we provide access to standard templates
> via a customised toolbar in Word.  Due to changes in working practises by
> business area we would like to adapt the toolbar to only view certain
> templates dependant on NT Group membership.  Is it possible using VB or
VBA
> to customise the toolbar in such a way that it will automatically show the
> appropriate view as determined by the NT access.  For further info we are
> running NT 4 SP5 and Office 97.

> Paul



Thu, 26 Feb 2004 23:29:58 GMT  
 NT user name & user groups
APC IT wrote

Quote:
>  Is it possible using VB or VBA
> to customise the toolbar in such a way that it will automatically show
> the appropriate view as determined by the NT access.

For Global Groups, as Neo has already suggested, you can call the
NetUserGetGroups API function. Try this code.

' *** Code Start ***
Private Declare Function NetUserGetGroups _
    Lib "netapi32.DLL" _
    (servername As Any, _
    username As Any, _
    ByVal level As Long, _
    bufptr As Long, _
    ByVal prefmaxlen As Long, _
    entriesread As Long, _
    totalentries As Long) _
    As Long

Private Declare Function NetApiBufferFree _
    Lib "netapi32.DLL" _
    (ByVal lpBuffer As Long) _
    As Long

Private Declare Sub CopyMem _
    Lib "kernel32" Alias "RtlMoveMemory" _
    (Destination As Any, _
    Source As Any, _
    ByVal Length As Long)

Private Declare Function lstrlenW _
    Lib "kernel32" _
    (ByVal lpString As Long) _
    As Long

Private Declare Function FormatMessage _
    Lib "kernel32" Alias "FormatMessageA" _
    (ByVal dwFlags As Long, _
    ByVal lpSource As Long, _
    ByVal dwMessageId As Long, _
    ByVal dwLanguageId As Long, _
    ByVal lpBuffer As String, _
    ByVal nSize As Long, _
    Arguments As Long) _
    As Long

Private Type GROUP_USERS_INFO_0
    grui0_name As Long
End Type

Private Const NERR_Success = 0
Private Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000

Function fEnumNetworkGroups( _
                ByVal strUserName As String, _
                Optional ByVal strServerName As String) _
                As VBA.Collection
'
'  Enumerates Global groups for a given user account
'   If ServerName is not specified in the arguments,
'   then local machine is assumed.
'
'   Win NT / Win2K ONLY
'
On Error GoTo ErrHandler
Dim pBuf As Long, GrpInfo As GROUP_USERS_INFO_0
Dim abytUser() As Byte, abytServer() As Byte
Dim lngLevel As Long, i As Long
Dim lngPrefMaxLen As Long
Dim lngEntriesRead As Long
Dim lngTotalEntries As Long
Dim lngRet As Long
Dim colOut As VBA.Collection

    lngPrefMaxLen = -1
    Set colOut = New VBA.Collection

    If (Len(strServerName)) Then
        abytServer = "\\" & strServerName
    Else
        abytServer = vbNullChar & vbNullChar
    End If

    abytUser = strUserName

    lngRet = NetUserGetGroups( _
                    abytServer(0), _
                    abytUser(0), _
                    0, _
                    pBuf, _
                    lngPrefMaxLen, _
                    lngEntriesRead, _
                    lngTotalEntries)

    If (lngRet = NERR_Success) Then
        For i = 0 To lngTotalEntries - 1
            Call CopyMem(GrpInfo, _
                ByVal (pBuf + (i * Len(pBuf))), _
                Len(GrpInfo))
            colOut.Add _
                fStrFromPtrW(GrpInfo.grui0_name)
        Next
    Else
        With Err
            .Raise .LastDllError, "fEnumNetworkGroups", fAPIErr
(.LastDllError)
        End With
    End If

    Set fEnumNetworkGroups = colOut
    Call NetApiBufferFree(pBuf)
    Set colOut = Nothing
    Exit Function
ErrHandler:
    Call NetApiBufferFree(pBuf)
    Set colOut = Nothing
    With Err
        .Raise .Number, .Source, .Description, .HelpFile, .HelpContext
    End With
End Function

Private Function fStrFromPtrW(pBuf As Long) As String
Dim lngLen As Long
Dim abytBuf() As Byte

    ' Get the length of the string at the memory location
    lngLen = lstrlenW(pBuf) * 2
    ' if it's not a ZLS
    If lngLen Then
        ReDim abytBuf(lngLen)
        ' then copy the memory contents
        ' into a temp buffer
        Call CopyMem( _
                abytBuf(0), _
                ByVal pBuf, _
                lngLen)
        ' return the buffer
        fStrFromPtrW = abytBuf
    End If
End Function

Private Function fAPIErr(ByVal lngErr As Long) As String
Dim strMsg As String
Dim lngRet As Long
    strMsg = String$(1024, 0)
    lngRet = FormatMessage( _
                    FORMAT_MESSAGE_FROM_SYSTEM, 0&, _
                    lngErr, 0&, strMsg, Len(strMsg), ByVal 0&)
    If lngRet Then
        fAPIErr = Left$(strMsg, lngRet)
    End If
End Function
' *** Code end ***

  -- Dev



Fri, 27 Feb 2004 06:55:41 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Getting the User Group name using Current User Function

2. !!!Please Help: How do I get the Users group name from my NT Server 3.51

3. How do I get the Users group name from my NT Server

4. Compare NT groups & users function

5. How to access NT user & group

6. How to get user id an user name on NT and Win95

7. LDB Viewer -- Need to get NT user login name in addition to computer name

8. Accessing Users and User Groups

9. How to copy user group to another user?

10. Script that remotely moves local users from Administrators to Power Users group

11. How can I get List of User Groups of specific user

12. how to know the user groups to which a given user belongs

 

 
Powered by phpBB® Forum Software