Active directory User Name and Password in C#

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi experts, i need help here, i am doing windows console application to list out the Active Directory User name, here is my code

static void Main(string[] args)<br/>
{<br/>
string groupName = "Domain Users";<br/>
string domainName = "ADtest.com";<br/>
<br/>
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, domainName);<br/>
GroupPrincipal grp = GroupPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, groupName);<br/>
<br/>
if (grp != null)<br/>
{<br/>
foreach (Principal p in grp.GetMembers(false))<br/>
{<br/>
Console.WriteLine(p.SamAccountName + " - " + p.DisplayName);<br/>
}<br/>
<br/>
grp.Dispose();<br/>
ctx.Dispose();<br/>
Console.ReadLine();<br/>
}<br/>
else<br/>
{<br/>
Console.WriteLine("nWe did not find that group in that domain, perhaps the group resides in a different domain?");<br/>
Console.ReadLine();<br/>
}<br/>
}<br/>
<br/>
However i got the following error<br/>
<br/>
An unhandled exception of type System.DirectoryServices.DirectoryServicesCOMException <br/>
occurred in System.DirectoryServices.dll<br/>
<br/>
Additional information: Logon failure: unknown user name or bad password.<br/>
<br/>
where should i assign User name and password?
Thanks in advance...

View the full article
 
Back
Top