Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NDiscover a Users NT Groups

Status
Not open for further replies.

u104741

MIS
Aug 26, 2003
94
GB
I know its possible t discover the current users NT user name with VBA, but it it possible to also discover what NT User Groups they belong too?

hope someone can help?
jj
 
u104741,
Give this a try.
Code:
Public Function GetUserGroup(Domain As String, User As String) As String
Dim objIADsUser As IADsUser
Dim objGroup As IADsGroup
Dim strOutput As String
strOutput = "WinNT://" & Domain & "/" & User & ",User"
Set objIADsUser = GetObject(strOutput)
For Each objGroup In objIADsUser.Groups
  If GroupInfo <> "" Then
    strOutput = strOutput & ";" & objGroup.Name
  End If
Next objGroup
Set objIADsUser = Nothing
Err_Handler:
If Err.Number <> 0 Then
  strOutput = strOutput & "Active Directory property cannot be found"
  Resume Next
End If
GetUserGroup = strOutput
End Function

Hope this helps,
CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top