Page 1 of 1 1
Topic Options
#118581 - 2004-04-26 05:17 PM Connecting to LDAP ?
futureline Offline
Fresh Scripter

Registered: 2003-12-12
Posts: 10
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")



Top
#118582 - 2004-04-26 05:47 PM Re: Connecting to LDAP ?
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
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


Top
#118583 - 2004-04-26 06:03 PM Re: Connecting to LDAP ?
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
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


Top
#118584 - 2004-04-26 11:05 PM Re: Connecting to LDAP ?
futureline Offline
Fresh Scripter

Registered: 2003-12-12
Posts: 10
@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.


Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 507 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.049 seconds in which 0.021 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org