开发者

PrincipalContext & UserPrincipal how to know when password expires?

I hav开发者_StackOverflowe a UserPrincipal object with a lot of properties, but I cannot find a property for the date that the password expires.

How can this be done?


This is the simplest approach I was able to come up with...

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);


Note #1: ActiveDs is listed on the COM tab of the Add Reference dialog as Active DS Type Library

Note #2: As far as I can tell, the PasswordExpirationDate is in UTC time.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜