vbscript - 通过 VBscript/ADO 访问 LDAP 服务器

标签 vbscript ldap ado

当绑定(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, and cn 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/

相关文章:

algorithm - 如何解决余数函数?

active-directory - 使用 Microsoft Active Directory 进行群体 LDAP 配置

mysql - 需要一个使用 adoconection 的示例来避免 mysql 服务器消失

error-handling - 如何获得一个值,该值指示Recordset.Find是否找到了任何东西?

delphi - 在 ADO 数据集过滤器中使用 LIKE 和 '%'

xml - 打开文件对话框以选择 XML 文件

windows - 根据屏幕形状或停靠状态自动更改 Windows 7 任务栏位置

windows - 使用 vbscript 从 WMI 类获取描述

c# - .NET LDAP 路径实用程序 (C#)

java - 如何在没有管理员用户的情况下通过 JNDI 在 Active Directory 中更改过期密码