the issue is pertaining to the amount of time spent in looping in the code.
It's purpose if to return all the OUs that contain either user or computer objects.
Once it finds one, there is no longer any reason to keep foreaching.
by adding the goto, the runtime on my network goes from about 20 seconds to 4 seconds.
This will make McAfeeManager and some of the other kforms apps that use EnumOUs() much faster.
Code:
Function EnumOUs($LDAP, $Filter)
dim $aFilter[0], $pos, $objOU, $i, $j
if $Filter <> 'user' $Filter = 'computer' endif
$objOU = GetObject($LDAP)
if not VarTypeName($objOU)='Object' exit 1 endif
$aFilter[0] = $Filter
$objOU.Filter = $aFilter
for each $item in $objOU
$PBar1.Value = iif($PBar1.Value < $PBar1.Max,$PBar1.Value + 1,0) ;for progress bar only
if $item.class = $Filter
$i = $LDAP
goto jump
endif
next
:jump
$aFilter[0] = "organizationalUnit"
$objOU.Filter = $aFilter
for each $item in $objOU
$PBar1.Value = iif($PBar1.Value < $PBar1.Max,$PBar1.Value + 1,0) ;for progress bar only
$Name = $item.Name
$pos = instrrev($LDAP,"/")
$DN = Left($LDAP,$pos) + $Name + ", " + substr($LDAP, $pos+1)
$j = EnumOUs($DN, $Filter)
if $j
$i = iif($i,$i +"|"+ $j,$j)
endif
next
$EnumOUs = $i
Endfunction