2011-04-04 12 views

Respuesta

7

Este es el método más sencillo que era capaz de llegar a ...

using System.DirectoryServices; 
using System.DirectoryServices.AccountManagement; 
using ActiveDs; 

//... 

PrincipalContext domain = new PrincipalContext(ContextType.Domain); 
UserPrincipal user = UserPrincipal.FindByIdentity(domain, "username"); 
DirectoryEntry entry = (DirectoryEntry)user.GetUnderlyingObject(); 
IADsUser native = (IADsUser)entry.NativeObject; 
Console.WriteLine(user.GivenName + "'s password will expire on " + native.PasswordExpirationDate); 


Nota # 1: ActiveDs aparece en la pestañaCOM del Agregar referencia de diálogo como Active DS Type Library

Nota n. ° 2: Por lo que puedo decir, el PasswordExpirationDate está en hora UTC.

+0

Gran respuesta. ¡Gracias! un consejo: a veces, utilizar 'FindByIdentity' es muy lento. principalmente en máquinas locales. en estos casos, es mejor usar 'PrincipalSearcher' – itsho

+0

Normalmente no utilizo las clases" * Principal * ". Prefiero los objetos DirectoryEntry y DirectorySearcher. En mis pruebas, tienden a ser más rápidos. –

+0

¿En qué ensamblaje viven los ActiveDs? – Bartosz

Cuestiones relacionadas