当绑定(bind)到 LDAP 服务器时,ADO 能否访问 ADsPath 和 Name 以外的属性?
下面是我用来绑定(bind)和查询 Internet 上的 LDAP 服务器的代码:
Set ado = CreateObject("ADODB.Connection")
ado.Provider = "ADSDSOObject"
ado.Properties("User ID") = ""
ado.Properties("Password") = ""
ado.Properties("Encrypt Password") = False
ado.Open "NameSearch"
serverName = "xxxxxx.xxxx.xxx"
filterStr = "(objectClass=*)"
Set Ol= ado.Execute("<LDAP://" & serverName & ">;" & filterStr & ";ADsPath;SubTree")
While Not Ol
WScript.Echo Ol.Fields(0).value
Ol.MoveNext
Wend
还有如何将上述代码中的搜索库分配给“o=xxxxxx University;c=US”?
最佳答案
参见 How To Use ADO to Access Objects Through an ADSI LDAP Provider .
The connection object Execute method's CommandText (first object) is an LDAP query composed of four elements separated by semicolons, in the following format:
<LDAP://server/adsidn>;ldapfilter;attributescsv;scope
where
adsidn
is the distinguished name (DN) of the starting point for your query expressed ADsPath format with "/" separators and the root of the namespace to the left. You can also use an X.500 style attributed name format with the relative distinguished names separated by commas and the root of the name space to the right.To return the
ADsPath
,class
, andcn
attributes of all the objects in all the recipient containers in an Exchange server, you can use the following CommandText (in URL format):
LDAP:; (objectClass=*);ADsPath,objectClass,cn;子树
综合来看,
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Set conn = New ADODB.Connection
conn.Provider = "ADSDSOObject"
conn.Open "ADs Provider"
Set rs = conn.Execute( _
"<LDAP://server/o=organization/o=xxxxxx University/c=US>;" _
& "(objectClass=*);ADsPath,objectClass,cn;subtree")
While Not rs.EOF
Debug.Print rs.Fields(0).Value, rs.Fields(1).Value, _
rs.Fields(2).Value
rs.MoveNext
Wend
conn.Close
关于vbscript - 通过 VBscript/ADO 访问 LDAP 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/972847/