treeview AD code inside - need help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark Rezansoff

    treeview AD code inside - need help

    I have two examples of populating a treeview with AD
    information below.
    example A does exactly what I want, starts at the AD tree,
    but is really slow to generate.
    examble B gives more information, but is really fast.
    example B displays all the providers (ie. WinNT, NWcompat,
    NDS, IIS, and LDAP) I just want it to start at the top
    level of my AD tree. (LDAP only)

    This way the end user (help desk) can drill down the tree
    to get to the user or OU that they are modifying.
    -------------
    examples below
    -------------
    example A
    -------------
    Private Sub Form_Initialize ()
    Dim strBase As String
    Dim strUserBase As String
    Dim oRoot As Object
    Dim oOu As Object
    Dim rootnode As Node

    Set oRoot = GetObject("LDAP ://RootDse")
    strBase = oRoot.Get("defa ultNamingContex t")
    strUserBase = Replace(strBase , "DC=", "")
    strUserBase = Replace(strUser Base, ",", ".")
    TreeView1.Image List = ImageList1
    Set oOu = GetObject("LDAP ://" & strBase)
    Set rootnode = TreeView1.Nodes .Add(, , strBase,
    strUserBase, 3)
    rootnode.Select ed = False
    Call AddOUs(oOu, rootnode)

    End Sub

    Sub AddOUs(oOu As Object, Node As Node)
    Dim nd As Node
    Dim ou As Object
    Dim oNextOU As Object

    oOu.Filter = Array("organiza tionalunit")

    For Each ou In oOu
    Set nd = TreeView1.Nodes .Add(Node, tvwChild,
    ou.ADsPath, Replace(ou.Name , "OU=", ""), 1)
    Set oNextOU = GetObject(ou.AD sPath)
    Call AddOUs(oNextOU, nd)
    Next

    End Sub
    -------------
    example A
    -------------

    Option Explicit
    Private Sub Form_Load()
    Dim myADS As IADs
    Dim Member As IADs
    Dim DirectoryObject As IADs

    On Error Resume Next
    Set myADS = GetObject("ads: ")

    For Each Member In myADS
    Me.TreeView1.No des.Add , , Member.ADsPath, Member.Name
    + "(" + Member.ADsPath + ")"
    Me.TreeView1.No des.Add Member.ADsPath, tvwChild,
    Member.ADsPath + ";Dummy", "Dummy Node"
    Next

    End Sub

    Private Sub TreeView1_Expan d(ByVal Node As
    MSComctlLib.Nod e)
    Dim adsParent As IADsContainer
    Dim adsChild As IADs

    On Error GoTo Error_Handler:

    'Check to see whether this node has been previously
    expanded...
    If Node.Children = 1 Then
    'There is only one child node. Is it a dummy node?
    If Node.Child.Key = Node.Key + ";Dummy" Then
    'Yes.
    'Delete it
    Me.TreeView1.No des.Remove Node.Child.Key
    'Create real children...
    Set adsParent = GetObject(Node. Key)
    For Each adsChild In adsParent
    Me.TreeView1.No des.Add Node.Key, tvwChild,
    adsChild.ADsPat h, adsChild.Name + " (" + adsChild.ADsPat h
    + ")"
    Me.TreeView1.No des.Add adsChild.ADsPat h,
    tvwChild, adsChild.ADsPat h + ";Dummy", "Dummy Node"
    Next
    End If
    End If

    Error_Handler:
    End Sub


    Please help modify the fast one to only display the AD
    (ldap) provider.
    Thanks,
    Mark


Working...