English 中文(简体)
在 VBS 中执行 OpenLDAP 搜索
原标题:Executing OpenLDAP searches in VBS

我正试图将 Thunderbird/ Firefox 配置的定制脚本从 OS X 到 Windows 7. 在 OS X 上,它们非常简单, 使用 < code> ldapsearch - x - h ldap.place.edu uid= "username" 从 OpenLDAP 服务器上检索电子邮件地址、 真实姓名等, 然后在应用程序装入前将这些变量丢入各种配置文件 。

在 Windows 上,这要复杂得多, 我开始尝试使用与 Windows Server 2003 相联的 search.vbs 活动目录/ Ldap 工具, 但它不正确, 我还试图简单地写一个快速 vbs 脚本来连接和查询, 但我总是会收到错误, 要么服务器将不处理请求, 要么只是失败... 这是我最新的 vbs 脚本, 完全无法跳出...

Dim oConn,oRS,vSearch,vCount,vMailList,vValue,vProblem,vMsg

vProblem = False

vSearch = "(uid=username)"

Set oConn = CreateObject("ADODB.Connection")
oConn.Provider = "ADsDSOObject"
oConn.Open "ADs Provider", "ou=people,dc=place,dc=edu"

Set oRS = oConn.Execute("<LDAP://ldap.place.edu/dc=edu/dc=place>;" & vSearch &_";cn,mail")

vCount = 1
While not oRS.EOF

   For Each vValue in oRS.Fields(0).value
      WScript.Echo vValue
   Next

vCount = vCount + 1
oRS.MoveNext
Wend
最佳回答

稍早之前就想通了,完全忘记了这一点,所以是这样的。我意识到我试图连接到一个匿名服务器,但提供了一个 DN,而意味着一个密码级别的认证,而不是我需要的简单版本。

 Server name
sRoot = "LDAP://server"    
Dim oDS: Set oDS = GetObject("LDAP:")
 Don t provide a DN for anonymous authentication, also &H0010 implies simple auth mode
Dim oAuth: Set oAuth = oDS.OpenDSObject(sRoot, "", "", &H0010)
Dim oConn: Set oConn = CreateObject("ADODB.Connection")
oConn.Provider = "ADSDSOObject"
oConn.Open "Ads Provider", sDN
Dim rs
 Execute query
Set rs = oConn.Execute("<" & sRoot & ">;(uid=testuser);cn,mail;subtree")
 retrieve values
z = rs.Fields.Item(0).Value
x = rs.Fields.Item(1).Value
问题回答

暂无回答




相关问题
Why running a service as Local System is bad on windows?

I am trying to find out the difference between difference service account types. I tumbled upon this question. The answer was because it has powerful access to local resources, and Network Service ...

Programmatically detect Windows cluster configuration?

Does anyone know how to programatically detect that a Windows server is part of a cluster? Further, is it possible to detect that the server is the active or passive node? [Edit] And detect it from ...

get file icon for Outlook appointment (.msg)

I ve read Get File Icon used by Shell and the other similar posts - and already use SHFileInfo to get the associated icon for any given extension, and that works great. However, Outlook uses ".msg" ...

Identifying idle state on a windows machine

I know about the GetLastInputInfo method but that would only give me the duration since last user input - keyboard or mouse. If a user input was last received 10 minutes ago, that wouldn t mean the ...

Terminating a thread gracefully not using TerminateThread()

My application creates a thread and that runs in the background all the time. I can only terminate the thread manually, not from within the thread callback function. At the moment I am using ...

热门标签