我最初使用 LDAP 的目的是返回当前是活跃员工的指定组的所有活跃成员。
我来到了这个解决方案:
Public Const ADConString = "Provider=ADsDSOObject;
Encrypt Password=False;
Integrated Security=SSPI;
Data Source=
LDAP://Domain:Numbers/DC=ROOT,
DC=Someplace,OU=SomePlace;
Mode=Read
Bind Flags=0;ADSI Flag=-2147483648"
Public Function getActiveDirectoryGroup(groupName As String)
Dim cmd As ADODB.Command
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim test As Variant
Set cmd = CreateObject("ADODB.Command")
Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
cn.Open ADConString
cmd.CommandText =
"SELECT sn,adspath,cn,givenname,userAccountControl
FROM 'LDAP://RootPlace _
"WHERE MemberOf='cn=" & groupName &
",CN=SomePlace,DC=KMC,DC=SomePlace' " & _
"AND userAccountControl<>514
AND sn <>'name1' AND sn <>'name2'
AND sn <>'name3' " & _
"ORDER BY givenname"
Debug.Print cmd.CommandText
cmd.ActiveConnection = cn
Set rs = cmd.execute
groupPath = rs.Fields("adspath").Value
Do While Not rs.EOF
'Debug.Print rs.Fields("adspath").Value
Debug.Print rs.Fields("givenname").Value & " "
& rs.Fields("sn").Value & " "
& rs.Fields("userAccountControl")
'Debug.Print rs.Fields("cn").Value
rs.MoveNext
Loop
End Function
现在,如果你将它传递给一个组,这个解决方案就可以工作,但我想扩展它,以便有人可以只抓住活跃成员或摆脱sn <>'name1' AND sn <>'name2' AND sn<>'name3'
条件。
到目前为止,我已经建立了这个类
Option Compare Database
Option Explicit
Private pADConnectionString As String
Private pRootLocation As String
Private pGroupName As String
Private Sub class_Initialize()
pADConnectionString = "Provider=ADsDSOObject;
Encrypt Password=False;
Integrated Security=SSPI;
Data Source=
LDAP://Domain:Numbers/DC=ROOT,
DC=Someplace,OU=SomePlace;
Mode=Read
Bind Flags=0;ADSI Flag=-2147483648"
pRootLocation = getNC()
End Sub
Sub retreiveUsers()
End Sub
Public Property Get ADConnectionString() As Double
ADConnectionString = pADConnectionString
End Property
Public Property Let ADConnectionString(connectionString As Double)
pADConnectionString = connectionString
End Property
Function getNC()
Set objRoot = GetObject("LDAP://RootDSE")
getNC = objRoot.Get("defaultNamingContext")
End Function
Public Property Get groupName() As String
groupName = pGroupName
End Property
Public Property Let groupName(group As String)
pGroupName = group
End Property
我对类有点生疏,我不太确定如何在WHERE
这个类中引入动态语句。那么,我应该继续沿着这条路走下去吗?如果可以,我可以考虑采取哪些解决方案来处理该WHERE
条款?
我正在考虑使用一些草率的东西,例如将用户发送的内容附加到已应用于新whereStatement
私有变量的内容的设置器,这样它就可以继续附加到WHERE
子句。我担心的是,如果没有完全清楚,我将无法删除单个条件语句,例如sn<>'Name1'