1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
public class ADInteraction
{
// Variable of connection string to Active Directory
DirectoryEntry Ldap;
// Connecion to Active Directory
public bool Connection(string domainNameServer, string user, string password)
{
try
{
Ldap = new DirectoryEntry("LDAP://" + domainNameServer, user, password);
object connect = Ldap.NativeObject;
MessageBox.Show("You are connected with " + domainNameServer + "'s Active Directory.");
return true;
}
catch (Exception Ex)
{
MessageBox.Show("Le serveur n'est pas joignable ou les données de connexion sont incorrectes\n Veuillez réessayer s'il vous plaît.");
return false;
}
}
// Disconnection to Active Directory
public bool Disconnection()
{
try
{
Ldap.Close();
MessageBox.Show("The connection width Active Directory was stopped");
return true;
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message);
return false;
}
}
} |
Partager