From: Z on
I'm connecting to AD LDAP via the objDSObject query to get the UserDN
for a given account.

I have written the code that allows me to bind to the AD LDAP
successfully but not sure how to query the UserDN for a given
user............ this is my progress so far allowing me to bind to the
AD LDAP sucessfully.....

I can't figure out how to use the objDSO.OpenDSObject command to get
the UserDN name ......... can anyone advise how this can be done ??

'On Error Resume Next


' --- Constants must be declared. ---
Const ADS_SECURE_AUTHENTICATION = 1
Const ADS_SERVER_BIND = 512


'--- Admin Credentials ----
strUsername = "gg\administrator"
strPassword = "password"


' --- Use OpenDSObject to bind with credentials ---
Set oDSObj = GetObject("LDAP:")
' ServerName is Netbios name
Set oAuth = oDSObj.OpenDSObject("LDAP://labdc3/dc=gg,dc=com",
strUsername, strPassword, _
ADS_SECURE_AUTHENTICATION + ADS_SERVER_BIND)
If Err.Number <> 0 Then
MsgBox "Logon failure: unknown user name or bad password."
End If


MsgBox "You have successfully bound to : " & oAuth.Get("Name") & " as "
& strUsername


' Continue with script to perform operation on AD...

' Constants for the NameTranslate object.

Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1

' Specify the NetBIOS name of the domain and the NT name of the user.
strNTName = "gg\testuserA"

' Use the NameTranslate object to convert the NT user name to the
' Distinguished Name required for the LDAP provider.
Set objTrans = CreateObject("NameTranslate")

' Initialize NameTranslate by locating the Global Catalog.
objTrans.Init ADS_NAME_INITTYPE_GC, ""
' Use the Set method to specify the NT format of the object name.
objTrans.Set ADS_NAME_TYPE_NT4, strNTName

' Use the Get method to retrieve the RPC 1779 Distinguished Name.
strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)

' Bind to the user object in Active Directory with the LDAP provider.
Set objUser = GetObject("LDAP://" & strUserDN)

MsgBox strUserDN

Thanks in advance