1 |
VERSION 5.00 |
2 |
Begin VB.Form Form1 |
3 |
Caption = "Form1" |
4 |
ClientHeight = 3195 |
5 |
ClientLeft = 4920 |
6 |
ClientTop = 2910 |
7 |
ClientWidth = 4680 |
8 |
LinkTopic = "Form1" |
9 |
ScaleHeight = 3195 |
10 |
ScaleWidth = 4680 |
11 |
Begin VB.CommandButton Command1 |
12 |
Caption = "Command1" |
13 |
Height = 375 |
14 |
Left = 2520 |
15 |
TabIndex = 0 |
16 |
Top = 2520 |
17 |
Width = 1455 |
18 |
End |
19 |
End |
20 |
Attribute VB_Name = "Form1" |
21 |
Attribute VB_GlobalNameSpace = False |
22 |
Attribute VB_Creatable = False |
23 |
Attribute VB_PredeclaredId = True |
24 |
Attribute VB_Exposed = False |
25 |
Option Explicit |
26 |
|
27 |
Dim buf As String |
28 |
|
29 |
Private Sub Command1_Click() |
30 |
|
31 |
' 4. searching - via ADODB |
32 |
Dim adoConn As ADODB.Connection |
33 |
Dim oRecordSet As ADODB.Recordset |
34 |
Dim oField As ADODB.Field |
35 |
Dim objPath As String |
36 |
|
37 |
buf = "" |
38 |
|
39 |
' open connection to ldap-server |
40 |
Set adoConn = CreateObject("ADODB.Connection") |
41 |
adoConn.Provider = "ADsDSOObject" |
42 |
'con.Open "Active Directory Provider", "cn=admin,o=santam za", "nomad" |
43 |
adoConn.Open "Active Directory Provider", "", "" |
44 |
|
45 |
Set oRecordSet = adoConn.Execute("<LDAP://192.168.10.1/o=Tunemedia,c=de>;(&(objectClass=*));ADsPath;subTree") |
46 |
|
47 |
buf = buf & "RecordCount: " & oRecordSet.RecordCount & vbCrLf |
48 |
|
49 |
' loop through result-set |
50 |
While Not oRecordSet.EOF |
51 |
|
52 |
' Output each field and value to the debug window |
53 |
For Each oField In oRecordSet.Fields |
54 |
buf = buf & "{" & oField.Name & "}" + " = " + oField.Value & vbCrLf |
55 |
Next |
56 |
|
57 |
' get full path to ldap-object ... |
58 |
objPath = oRecordSet.Fields.Item("ADsPath") |
59 |
' ... and dump it. (FYI: uses "EnumeratePropertyValue" from "ADsHelper" to serialize object) |
60 |
dumpDSObjectByPath objPath |
61 |
|
62 |
buf = buf & "-------------------------------------" & vbCrLf |
63 |
|
64 |
' next result-entry |
65 |
oRecordSet.MoveNext |
66 |
|
67 |
Wend |
68 |
|
69 |
' close result-handle |
70 |
oRecordSet.Close |
71 |
|
72 |
' close connection |
73 |
adoConn.Close |
74 |
|
75 |
MsgBox buf |
76 |
|
77 |
End Sub |
78 |
|
79 |
Function GetDSObject(sDN, sUserName, sPassword) |
80 |
Dim objLDAP |
81 |
Dim obj |
82 |
|
83 |
Set objLDAP = GetObject("LDAP:") |
84 |
Set obj = objLDAP.OpenDSObject(sDN, sUserName, sPassword, 0) |
85 |
Set GetDSObject = obj |
86 |
End Function |
87 |
|
88 |
Function dumpDSObjectByPath(objPath As String) |
89 |
|
90 |
Dim myContainer As IADsContainer |
91 |
Dim myObj As IADs |
92 |
|
93 |
Dim myPropertyList As IADsPropertyList |
94 |
Dim myPropertyEntry As PropertyEntry |
95 |
Dim propCount As Long |
96 |
Dim i As Long |
97 |
Dim strValues As String |
98 |
|
99 |
Set myPropertyList = GetObject(objPath) |
100 |
myPropertyList.GetInfo 'populate the cache |
101 |
propCount = myPropertyList.PropertyCount |
102 |
|
103 |
' --Loop through each of the properties and output their values --- |
104 |
For i = 0 To propCount - 1 |
105 |
strValues = "" |
106 |
Set myPropertyEntry = myPropertyList.Next |
107 |
EnumeratePropertyValue myPropertyEntry, strValues |
108 |
buf = buf & " " & "{" & myPropertyEntry.Name & "}" + " = " + strValues & vbCrLf |
109 |
Next |
110 |
|
111 |
Set myPropertyList = Nothing |
112 |
|
113 |
End Function |