Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Active Directory, how to locate two forrests

Status
Not open for further replies.

Kruzer

Programmer
Jun 16, 2000
117
US
I have code in a VB 6 app that scans thru a single forrest right now and I'm trying to figure out how to grab the second forrest. What does Global Catalog give me for Acive Directory? Both forrest can be accessed by the single server (MS domain), what code segements do I need to add to scan for the second forrest? Thanks in advance!


Code:
'ADO Connection object
Set con = CreateObject("ADODB.Connection")
con.Provider = "ADsDSOObject"
con.Open "Active Directory Provider"

'ADO Command object
Set ocommand = CreateObject("ADODB.Command")
ocommand.ActiveConnection = con
Set gc = GetObject("GC:")
For Each child In gc
    Set entpr = child
Next

ocommand.Properties("Page size") = 10000
ocommand.CommandText = "<" & entpr.ADsPath & ">;(&(objectCategory=group)(objectClass=group));distinguishedName;subTree"
Set rs = ocommand.Execute

rval = ""
rs.MoveFirst
While Not rs.EOF

    description = "(null)"
    intranet = "(null)"
    extranet = "(null)"
    countrycode = "(null)"
    department = "(null)"
    salesteam = "(null)"
    application = "(null)"
    departspecific = "(null)"
    financialcompany = "(null)"
    customer = "(null)"
    stellentcode = "(null)"
    computedcountry = "(null)"

    On Error GoTo nextelement
    dn = rs.Fields(0)
    timeObj = Timer
    writeDebugMessage ("time =" & timeObj & "- dn = " & dn)
    Set oGrp = GetObject("LDAP://" & dn)
    
    'Determine if this group should be included
    IncludeGroup = False
    
    On Error GoTo resetintranet
    oGrp.GetInfoEx Array("dimon-cmintranet"), 0
    intranet = oGrp.Get("dimon-cmintranet")
    'writeDebugMessage ("intranet = " & intranet)

    On Error GoTo resetextranet
    oGrp.GetInfoEx Array("dimon-cmextranet"), 0
    extranet = oGrp.Get("dimon-cmextranet")
    'writeDebugMessage ("extranet = " & extranet)

    If (getIntranet) Then
        If (intranet = "1") Then
            IncludeGroup = True
        End If
    End If
    
    If (getExtranet) Then
        If (extranet = "1") Then
            IncludeGroup = True
        End If
    End If
    
    
    If (IncludeGroup) Then

        description = oGrp.Get("cn")
        'writeDebugMessage ("description = " & description)
        
        oGrp.GetInfoEx Array("dimon-cmcountrycode", "dimon-cmdepartment", _
                             "dimon-cmsalesgroup", "dimon-cmapplication", _
                             "dimon-cmdepartmentspecific", "dimon-cmfinancialcompany", _
                             "dimon-cmextranetcustomer", "dimon-cmcode"), 0
                             
                             
        On Error GoTo resetcountrycode
        countrycode = oGrp.Get("dimon-cmcountrycode")
        'writeDebugMessage ("countrycode = " & countrycode)
        
        On Error GoTo resetdepartment
        department = oGrp.Get("dimon-cmdepartment")
        'writeDebugMessage ("department = " & department)
        
        On Error GoTo resetsalesteam
        salesteam = oGrp.Get("dimon-cmsalesgroup")
        'writeDebugMessage ("salesteam = " & salesteam)
        
        On Error GoTo resetapplication
        application = oGrp.Get("dimon-cmapplication")
        'writeDebugMessage ("application = " & application)
        
        On Error GoTo resetdepartspecific
        departspecific = oGrp.Get("dimon-cmdepartmentspecific")
        'writeDebugMessage ("departspecific = " & departspecific)
        
        On Error GoTo resetfinancialcompany
        financialcompany = oGrp.Get("dimon-cmfinancialcompany")
        'writeDebugMessage ("financialcompany = " & financialcompany)
        
        On Error GoTo resetcustomer
        customer = oGrp.Get("dimon-cmextranetcustomer")
        'writeDebugMessage ("customer = " & customer)
        
        On Error GoTo resetstellentcode
        stellentcode = oGrp.Get("dimon-cmcode")
        'writeDebugMessage ("stellentcode = " & stellentcode)
        
        If (department = "1" Or departspecific <> "(null)") Then
            If (stellentcode <> "(null)") Then
                computedcountry = Left(stellentcode, 2)
            End If
        End If
        
         If (countrycode = "1") Then
            If (stellentcode <> "(null)") Then
                stellentcode = Left(stellentcode, 2)
            End If
        End If
    
        If (Len(rval) > 0) Then
            rval = rval & ";"
        End If
        
        rval = rval & description & "^" & intranet & "^" & extranet & "^" & countrycode & "^" & _
                        department & "^" & salesteam & "^" & _
                        application & "^" & departspecific & "^" & financialcompany & "^" & customer & _
                        "^" & stellentcode & "^" & dn & "^" & computedcountry
        writeDebugMessage ("rval = " & rval)
        
    End If
    
mn:
    rs.MoveNext
Wend
 loadAllMetaForCache = rval
 
 writeDebugMessage ("----- End loadAllMetaForCache() ---------")
 
 Exit Function
 
nextelement:
    Resume mn
 
resetdescription:
    description = "(null)"
    Resume Next
resetintranet:
    intranet = "(null)"
    Resume Next
resetextranet:
    extranet = "(null)"
    Resume Next
resetcountrycode:
    countrycode = "(null)"
    Resume Next
resetdepartment:
    department = "(null)"
    Resume Next
resetsalesteam:
    salesteam = "(null)"
    Resume Next
resetapplication:
    application = "(null)"
    Resume Next
resetdepartspecific:
    departspecific = "(null)"
    Resume Next
resetfinancialcompany:
    financialcompany = "(null)"
    Resume Next
resetcustomer:
    customer = "(null)"
    Resume Next
resetstellentcode:
    stellentcode = "(null)"
    Resume Next

Dano
dan_kryzer@hotmail.com
What's your major malfunction
 
Some questions:
Why do you repeat Resume Next many times? May be the last Resume Next will be able to handle all the cases.

Why do use a combination of On Error GoTo ... and Resume Next? I guess due to the NULL field. Consider to use IsNull function to handle this.

Your loop below just loops throu all items in gc and the one that happens to be the last gets finally assigned to entpr. Does it seem strange?

For Each child In gc
Set entpr = child
Next


vladk
 
getIntranet and getExtranet...

Are they functions? If they are and independent of the loop then don't call them inside the loop all the time, use variables. Do they exclude each other? If yes, then why not to use if/else?

vladk

 
Assuming that getIntranet and getExtranet are variables, this pair of If blocks and the initializing line

IncludeGroup = False

If (getIntranet) Then
If (intranet = "1") Then
IncludeGroup = True
End If
End If

If (getExtranet) Then
If (extranet = "1") Then
IncludeGroup = True
End If
End If

can be replaced with just one line of code:

IncludeGroup = (intranet = "1" And getIntranet) Or (extranet = "1" And getExtranet)

vladk
 
The code is from an existing developer :) ...I want leverage the code (AD calls) he had with the new code. Thanks for the critiques.

getIntranet and getExtranet are function parameters passed when the function is called.

Code:
Public Function loadAllMetaForCache(ByVal getIntranet As Boolean, ByVal getExtranet As Boolean)

I'll make the code changes to the code, but do you code snippets that scan multiple forrests for AD?


Dano
dan_kryzer@hotmail.com
What's your major malfunction
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top