Searching for Domain controllers when dinding using a dc name

S

Sameh Ahmed

Hello there
I need to get a list of domain controllers to a domain I bind too using it's
name rather than the DN.
I am trying a query looking for objectClass=nTDSDSA but this returns 0
results
I am using VB.net 2.0
any ideas?
Here's my code
Thanks in advance.

Dim entry As New DirectoryServices.DirectoryEntry
entry.Path = "LDAP://" & TextBox1.Text
If RadioButton2.Checked = False Then
entry.Username = TextBox3.Text
entry.Password = TextBox2.Text
End If
entry.AuthenticationType = DirectoryServices.AuthenticationTypes.Secure
Dim searcher As New DirectoryServices.DirectorySearcher(entry)

Dim results As DirectoryServices.SearchResultCollection
Dim result As DirectoryServices.SearchResult
searcher.SearchScope = DirectoryServices.SearchScope.Subtree
searcher.Filter = "(objectClass=nTDSDSA)"
results = (searcher.FindAll())
Dim dcou As New DirectoryServices.DirectoryEntry
For Each result In results
dcou = result.GetDirectoryEntry
MsgBox(dcou.Name)
Next
 
J

Joe Richards [MVP]

Get the DNS name of the domain (use Translate to get the DN and convert the DC
part to a DNS name (i.e. remove the DC= and commas and put in the dots)) then
use DsGetDCOpen and the related functions.
 
J

Joe Kaplan \(MVP - ADSI\)

In .NET 2.0, this is much easier with
System.DirectoryServices.ActiveDirectory. Just call the GetDomain static
method on the Domain class and enumerate the DomainControllers property. It
does all the locator service stuff for you under the hood.

Joe K.
 
S

Sameh Ahmed

Thanks guys for the great help

Joe Kaplan (MVP - ADSI) said:
In .NET 2.0, this is much easier with
System.DirectoryServices.ActiveDirectory. Just call the GetDomain static
method on the Domain class and enumerate the DomainControllers property.
It does all the locator service stuff for you under the hood.

Joe K.
 
S

Sameh Ahmed

Hello
getting the current domain is easy.
but how can I choose the domain to which I want to bind?
thanks in advance.
 
J

Joe Kaplan \(MVP - ADSI\)

As I previously suggested, the GetDomain method allows you to specify a
domain.

Joe K.
 
J

Joe Kaplan \(MVP - ADSI\)

np.

Domain d = Domain.GetDomain(
new DirectoryContext(
DirectoryContextType.Domain,
"mydomain.com")
);
foreach (DomainController dc in d.DomainControllers)
{
Console.WriteLine(dc.ToString());
}

Joe K.
 
S

Sameh Ahmed

thanks a million

Joe Kaplan (MVP - ADSI) said:
np.

Domain d = Domain.GetDomain(
new DirectoryContext(
DirectoryContextType.Domain,
"mydomain.com")
);
foreach (DomainController dc in d.DomainControllers)
{
Console.WriteLine(dc.ToString());
}

Joe K.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top