Cannot search Active Directory when logged in as Local Administrator

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Tested Environment : Windows Server 2008 R2, .NET Framework 4
<span style="text-decoration:underline Issue
Im logged in to the machine as Local Administrator.
My requirement is to get some details of a a given domain user.
My code looks like this.
//this is the common user in the domain
string user = "generic_user";
//password of the common user
string password = "password";
//LDAP path
string strLdapPath = "LDAP://DC=####,DC=#####,DC=com";
DirectoryEntry entry = new DirectoryEntry(strLdapPath, user, password);
DirectorySearcher search = new DirectorySearcher(entry);
// this is the domain user of which I need to get info of
string strLdapUser = "userA";
search.Filter = string.Format("(sAMAccountName={0})", strLdapUser);
SearchResultCollection Res = search.FindAll();
// get email address
foreach (SearchResult res in Res)
{
uservalue = res.Properties["mail"][0].ToString();
}
But Im unable to get any info.. it throws the following exception.
"The specified domain either does not exist or could not be contacted"
Is there anything I have to do in order to retrieve info?
Note: This works fine when im running my application logged in as a domain user.
<br/>
<br/>

View the full article
 
Back
Top