Getting a listing of all the child domains

  • Thread starter Thread starter Saqib Ali
  • Start date Start date
S

Saqib Ali

Hi All,

I am trying to retrieve all the child domains for a given domain in a
VB applications. Will something like the following do the trick?

Dim enTry As DirectoryEntry = New DirectoryEntry("LDAP://" &
parentDomain)
Dim mySearcher As DirectorySearcher = New
DirectorySearcher(enTry)
Dim resEnt As SearchResult
mySearcher.Filter = ("(objectClass=domain)")

Thanks
saqib
http://doctrina.wordpress.com
 
I suggest looking at S.DS.ActiveDirectory and using the Domain.Children
property. It is much more straightforward.

Joe K.
 
Hi Joe,

Thanks for the response. I tried the following and it spits out
everything BUT the child domains
Dim objADObject As New DirectoryEntry("LDAP://" &
parentDomain)
Dim objChild As New DirectoryEntry
For Each objChild In objADObject.Children
Response.Write(objChild.Name & "<br/>")
Next objChild

Any thoughts? Thanks

saqib
http://doctrina.wordpress.com
 
Why didn't you try what I suggested instead (using the Domain class in
System.DirectoryServices.ActiveDirectory)? The method you are attempting to
use will not do what you want and even though it is definitely possible to
find the child domains using S.DS, it is much easier to do it with S.DS.AD
instead.

Joe K.
--
Joe Kaplan-MS MVP Directory Services Programming
Co-author of "The .NET Developer's Guide to Directory Services Programming"
http://www.directoryprogramming.net
--
Hi Joe,

Thanks for the response. I tried the following and it spits out
everything BUT the child domains
Dim objADObject As New DirectoryEntry("LDAP://" &
parentDomain)
Dim objChild As New DirectoryEntry
For Each objChild In objADObject.Children
Response.Write(objChild.Name & "<br/>")
Next objChild

Any thoughts? Thanks

saqib
http://doctrina.wordpress.com
 
Did you even look at the API? It is remarkably easy and should not require
much help:

Dim d as Domain = Domain.GetCurrentDomain()
For Each child as Domain in d.Children
Console.WriteLine(child.name)
Next

You may want to use one of the other methods for creating a domain object if
you want to start with a domain other than the current one.

Joe K.
 
Thanks Joe. The Domain.Children did the trick.

The reason I asked for a sample was that I couldn't get the Domain
class to work in VS 2003. Even thought I had added reference to the
System.DirectoryServices.dll

However once I upgraded to VS 2005 everything works fine.

Thanks
saqib
http://doctrina.wordpress.com
 
Back
Top