Thursday, January 22, 2009

C#: Connect ActiveDirectory

To Connect the Active Directory, use the following method



using System;
using System.DirectoryServices;
using System.Security.Principal;
using System.Runtime.InteropServices;
using System.Collections;

private System.DirectoryServices.DirectoryEntry AD = null;
private System.Boolean connected = false;

public System.Boolean Connect(string loginPath)
{
try
{
AD = new System.DirectoryServices.DirectoryEntry(loginPath);

connected = true;
}
catch (Exception e)
{
error = true;
connected = false;
errorLog.Append(e.ToString());
}
return connected;
}

No comments:

Post a Comment