"The following code examples show how to search for all users in a domain. It contains some basic required tasks such as using a C# try-catch or Visual Basic .NET try-catch-finally statement to catch errors and error handling for all the errors that can be thrown by the DirectorySearcher object."
http://msdn.microsoft.com/en-us/library/ms180885(v=vs.80).aspx[
^]
try
{
string username =@"your username"
string password =@"your password"
DirectoryEntry entry = new DirectoryEntry("LDAP://CN=users,DC=fabrikam,DC=com",username,password);
DirectorySearcher mySearcher = new DirectorySearcher(entry);
SearchResultCollection result = mySearcher.FindAll();
}
catch (System.Runtime.InteropServices.COMException)
{
System.Runtime.InteropServices.COMException exception = new System.Runtime.InteropServices.COMException();
Console.WriteLine(exception);
}
catch (InvalidOperationException)
{
InvalidOperationException InvOpEx = new InvalidOperationException();
Console.WriteLine(InvOpEx.Message);
}
catch (NotSupportedException)
{
NotSupportedException NotSuppEx = new NotSupportedException();
Console.WriteLine(NotSuppEx.Message);
}