futureline
(Fresh Scripter)
2004-04-26 05:17 PM
Connecting to LDAP ?

Here is my question.
I am trying to connect to LDAP but as the code that a member send me (Peter) did not work.
Now I am stuck. Here is what I think the problem. This piede of code cannot connect to LDAP. But I don’t know why. There is no error routine in the code so I don’t know why it is not connecting.

If I make a message:
MessageBox("LDAP://$userOU,dc=$DomainName,dc=$Toplevel","adsDomain =",16)
MessageBox("LDAP://cn=$Group,$GroupOU,dc=$DomainName,dc=$Toplevel","adsGroup =",16)
The values are filled by what appears to be good. But if I make a message for the value $adsDomain or $adsGroup they are empty.
Whats is it that’s going wrong.

Code:
; connecting to Ldap

$adsDomain = GetObject("LDAP://$userOU,dc=$DomainName,dc=$Toplevel")
$adsGroup = GetObject("LDAP://cn=$Group,$GroupOU,dc=$DomainName,dc=$Toplevel")




ShaneEP
(MM club member)
2004-04-26 05:47 PM
Re: Connecting to LDAP ?

Try checking the error values to see if it is failing or not. Since it's an object I dont think it would display anything if you tried to view $adsdomain or $adsgroup. You can view properties of the object however like...

$null=messagebox($adsGroup.name,"",0)

Code:

$adsGroup = GetObject("LDAP://cn=$Group,cn=$GroupOU,dc=$DomainName,dc=$Toplevel")
If @Error <> 0
$null = messagebox(@SError,@Error,0)
Endif



ShaneEP
(MM club member)
2004-04-26 06:03 PM
Re: Connecting to LDAP ?

You could also use the TranslateName UDF as it will help cut down on syntax errors when needing the ldap path. You could do something like...

Code:
$group = "Domain Admins"  ; The group you are trying to connect to
$ldapgroup = TranslateName (3,"",3,@Domain+"\"+$group,1)[0] ; Gets the LDAP path to the group

$adsGroup = GetObject("LDAP://"+$ldapgroup) ; Connects to the ldap path of the group

If @Error <> 0
$null = messagebox(@SError,@Error,0)
Else
$null=messagebox($adsGroup.name,"Success",0)
Endif

Function TranslateName ($InitType, $BindName, $LookupNameType, $LookupName, $ReturnNameType)
Dim $InitType, $BindName, $LookupNameType, $LookupName, $ReturnNameType
Dim $NameTranslate, $ReturnName, $Error, $ErrorText
$Error = 0
$ErrorText = ""
$ReturnName = ""
$NameTranslate = CREATEOBJECT ("NameTranslate")
$Error = @error
$ErrorText = @serror
if $Error = 0
$NameTranslate.Init ($InitType, $BindName)
$Error = @error
$ErrorText = @serror
if $Error = 0
$NameTranslate.Set ($LookupNameType, $LookupName)
$Error = @error
$ErrorText = @serror
if $Error = 0
$ReturnName = $NameTranslate.Get($ReturnNameType)
$Error = @error
$ErrorText = @serror
endif
endif
endif
$TranslateName = $ReturnName, $Error, $ErrorText
Endfunction



futureline
(Fresh Scripter)
2004-04-26 11:05 PM
Re: Connecting to LDAP ?

@CitrixMan

Yep that helped. I used the code to find my problem. (thats also a use for piece of code) and i found my problem.

Thanks Everything works now.