2008-11-27 5 views

Répondre

5

J'essaie juste d'obtenir le contexte actuel du domaine associé à l'utilisateur en cours d'exécution:

try { 
    var domain = Domain.GetCurrentDomain(); 
    /* Whatever i need from the domain */ 
} catch(ActiveDirectoryOperationException ex) { 
    MessageBox.Show("Cannot contact AD Server"); 
} 

Si vous voulez vous connecter à un autre domaine, vous pouvez essayer:

try { 
    var domain = Domain.GetDomain(
     new DirectoryContext(DirectoryContextType.Domain, "mydomain.local")); 
    /* Whatever i need from the domain */ 
} catch(ActiveDirectoryOperationException ex) { 
    MessageBox.Show("Cannot contact AD Server"); 
} 
+0

Ce va seulement fonctionner si la machine qui exécute le code est réellement connectée à ce domaine (ce qui n'est pas forcément le cas). – TheSmurf

+0

consultez ma mise à jour. – Yona

+0

J'essayais d'éviter les constructions try/catch, mais ça fait l'affaire! – Seiti

Questions connexes