C
CoolBreeze812
Hello,
I'm using the following code to get the list of computers joined to a
domain in Active Directory and using the System.DirectoryServices
namespace.
DirectoryEntry dirEntry = new DirectoryEntry("LDAP://spencenet.com");
DirectorySearcher dirSearch = new
DirectorySearcher(dirEntry);
dirSearch.Filter = "(objectClass=Computer)";
foreach (SearchResult sr in dirSearch.FindAll())
{
try
{
listBox1.Items.Add(sr.GetDirectoryEntry().Name.ToString().Substring(3));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "LDAP: Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
listBox1.SelectedIndex = 0;
}
The problem is that it returns all computers, both servers and
workstations. I would like to limit this to only servers being listed
in the listbox. I have tried objectClass=Server, but nothing was
returned and I haven't been able to find any other attribute that would
list only the servers in the domain.
I have a test domain setup and tried the code both on a Windows 2003
server and an XP workstation that is joined to the domain with the
objectClass=Server, both did not populate the listbox with only the
listing of the Windows 2003 server. FYI, I have the Windows 2003 server
configured with a role of Domain Controller and DNS Server only.
Does anyone know how I can retrieve only servers within an Active
Directory Domain?
Thanks,
-- Lance
I'm using the following code to get the list of computers joined to a
domain in Active Directory and using the System.DirectoryServices
namespace.
DirectoryEntry dirEntry = new DirectoryEntry("LDAP://spencenet.com");
DirectorySearcher dirSearch = new
DirectorySearcher(dirEntry);
dirSearch.Filter = "(objectClass=Computer)";
foreach (SearchResult sr in dirSearch.FindAll())
{
try
{
listBox1.Items.Add(sr.GetDirectoryEntry().Name.ToString().Substring(3));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "LDAP: Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
listBox1.SelectedIndex = 0;
}
The problem is that it returns all computers, both servers and
workstations. I would like to limit this to only servers being listed
in the listbox. I have tried objectClass=Server, but nothing was
returned and I haven't been able to find any other attribute that would
list only the servers in the domain.
I have a test domain setup and tried the code both on a Windows 2003
server and an XP workstation that is joined to the domain with the
objectClass=Server, both did not populate the listbox with only the
listing of the Windows 2003 server. FYI, I have the Windows 2003 server
configured with a role of Domain Controller and DNS Server only.
Does anyone know how I can retrieve only servers within an Active
Directory Domain?
Thanks,
-- Lance