VB icon

Get NT User Info (FullName, Groups) using ADSI

Email
Submitted on: 1/3/2015 9:28:00 AM
By: Shannon Norrell (from psc cd)  
Level: Not Given
User Rating: By 4 Users
Compatibility: VB 5.0, VB 6.0, VB Script, ASP (Active Server Pages)
Views: 2773
 
     Example code showing how one may extract NT Domain User information using ADSI (Active Directory Service Interfaces). This code simply extracts a user's FullName and lists the Groups to which he/she belongs, given his username. This code will work across domains, provided the correct authentication values (username, password) are inserted.
 

Windows API/Global Declarations:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
'**************************************
'Windows API/Global Declarations for :Get NT User Info (FullName, Groups) using ADSI
'**************************************
Must Reference the ActiveDS Type Library. (activeds.tlb)
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Get NT User Info (FullName, Groups) using ADSI
' Description:Example code showing how one may extract NT Domain User information using ADSI (Active Directory Service Interfaces).
This code simply extracts a user's FullName and lists the Groups to which he/she belongs, given his username.
This code will work across domains, provided the correct authentication values (username, password) are inserted.
' By: Shannon Norrell (from psc cd)
'
' Returns:Example from IMMEDIATE WINDOW:
==================================================
NT UserNameWebdood
FullNameShannon Norrell
This user belongs to the following NT Groups:
Domain Users
'
' Assumes:Uses ADSI (Active Directory Services) 2.0 or later.
'**************************************

Private oIADS As ActiveDs.IADsContainer
Private oUser As ActiveDs.IADsUser
Private oGroup As ActiveDs.IADsGroup
Private Sub Form_Load()
txtDomain = "MYDOMAIN"
usrName = "Administrator"
usrPassword = "sa"
usrNameOfInterest = "WebDood"
Set oIADS = GetObject("WinNT:").OpenDSObject("WinNT://" & txtDomain, usrName, usrPassword, 1)
Set oUser = oIADS.GetObject("user", usrNameOfInterest)
With oUser
 Debug.Print "NT UserName" & Space$(8) & .Name
 Debug.Print "FullName" & Space$(11) & .FullName
 Debug.Print "This user belongs to the following NT Groups:"
 For Each oGroup In .Groups
 Debug.Print vbTab & oGroup.Name
 Next
End With
End Sub


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Not Given category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.