现在的位置: 首页 > 综合 > 正文

LS函数:在AD中,查询指定用户条目

2013年05月21日 ⁄ 综合 ⁄ 共 1076字 ⁄ 字号 评论关闭
01 Function SearchAD(userName As String) As String  

02    Dim objConnection As Variant  
03    Dim objCommand As Variant  
04    Dim objRecordSet As Variant  
05    Const ADS_SCOPE_SUBTREE = 2
06 
07    On Error Goto errHandler    
08    Set objConnection = CreateObject("ADODB.Connection")
09    Set objCommand = CreateObject("ADODB.Command")
10    objConnection.Provider = "ADsDSOObject"
11    objConnection.Open "Active Directory Provider"
12    Set objCommand.ActiveConnection = objConnection
13    objCommand.Properties("Page Size") = 1000
14    objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
15    ' Note: 使用ADS中属性查询
16    ' 查询语句,相关语句可查询MSDN中相关对象
17    objCommand.CommandText = "SELECT * FROM 'http://www.cnblogs.com/hannover/admin/ldap://10.1.1.8/' WHERE cn='"+userName+"' "  
18 
19    Set objRecordSet = objCommand.Execute      
20    If ( objRecordSet.RecordCount = 0 ) Then
21        SearchLDAP="0"
22    Else
23        SearchLDAP="1"
24    End If
25    objRecordSet.close
26 
27    Exit Function
28errHandler:
29    Msgbox "Error is : " & Error$ & " at line number : " & Cstr(Erl) & " in SearchAD() " & " while processing user : " & userName
30    Exit Function
31End Function

抱歉!评论已关闭.