我有一个带有许多属性的UserPrincipal对象,但是找不到密码过期日期的属性。

如何才能做到这一点?

最佳答案

这是我能想到的最简单的方法...

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

注意#1:ActiveDs在“添加引用”对话框的“COM”选项卡上列为事件DS类型库

注意#2:据我所知,PasswordExpirationDate是UTC时间。

关于c# - PrincipalContext和UserPrincipal如何知道密码何时过期?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5535829/

10-10 13:00