Function SearchAD(userName As String) As String
Dim objConnection As Variant
Dim objCommand As Variant
Dim objRecordSet As Variant
Const ADS_SCOPE_SUBTREE = 2
On Error Goto errHandler
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
' Note: 使用ADS中属性查询
' 查询语句,相关语句可查询MSDN中相关对象
objCommand.CommandText = "SELECT * FROM 'LDAP://10.1.1.8' WHERE cn='"+userName+"' "
Set objRecordSet = objCommand.Execute
If ( objRecordSet.RecordCount = 0 ) Then
SearchLDAP="0"
Else
SearchLDAP="1"
End If
objRecordSet.close
Exit Function
errHandler:
Msgbox "Error is : " & Error$ & " at line number : " & Cstr(Erl) & " in SearchAD() " & " while processing user : " & userName
Exit Function
End Function
LS函数:在AD中,查询指定用户条目
最新推荐文章于 2021-04-28 16:14:26 发布