Automation - Retrieving a Property From an ADSI object

The following example retrieves a property directly from an ADSI object using the standard IADsUser interface and the Fullname property it supports.

Dim MyUser as IADsUser
Dim MyName as String
 
Set MyUser = GetObject("NDS://O=MyOrg/OU=SomeOU/CN=JamesSmith")
MyName = MyUser.Fullname
 

The following example retrieves a property by name from an object using IADs::Get. If the property is multivalued, IADs::GetEx must be used. Note that because IADsUser inherits from IADs, the methods supported by IADs are automatically accessible.

Dim MyUser as IADsUser
Dim MyName as String
 
set MyUser = GetObject("NDS://O=MyOrg/OU=SomeOU/CN=JamesSmith")
MyName = MyUser.Get("Fullname")
 

The following example uses IADsPropertyList using the Next method to retrieve all the properties on a given object from an LDAP server.

Dim MyVar As Variant
Dim MyADsPropList As IADsPropertyList
Dim MyADsObj As IADsOpenDSObject
Dim DN As String
Dim UserName As String
Dim Password As String
Dim propcount As Integer
 
'Bind to specific object
DN = "LDAP://MyServer/dc=Mydomain,dc=microsoft,dc=com,o=internet"
UserName = "cn=Administrator,cn=Users,dc=Mydomain,dc=microsoft,dc=com,o=internet"
Password = "password"
Set MyADsObj = GetObject("LDAP:")
Set MyADsPropList = MyADsObj.OpenDSObject(DN, UserName, Password, 0)
 
' Get the properties into the cache !
MyADsPropList.GetInfo
 
'Get the Number of Properties in the list and walk the list
propcount = MyADsPropList.PropertyCount
 
Debug.Print "There are ", propcount, " properties."
 
For i = 1 To propcount
    Set MyVar = MyADsPropList.Next
    Debug.Print "The property Name from Variant is "; MyVar.Name
Next
 
On Error Resume Next
' This call will fail !
Set MyVar = MyADsPropList.Next
If Err.Number Then
    Debug.Print Err.Number; " Occurred "
    Err.Clear
End If
 
' Now Reset the property Index and and then call next
' This will return the first value
MyADsPropList.Reset
Set MyVar = MyADsPropList.Next
Debug.Print "The first element in the list has the name ", MyVar.Name