主体上下文UserPrincipal如何知道密码何时过期? [英] PrincipalContext & UserPrincipal how to know when password expires?
本文介绍了主体上下文UserPrincipal如何知道密码何时过期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 UserPrincipal
对象,该对象具有很多属性,但是在密码到期之日找不到属性。
I have a UserPrincipal
object with a lot of properties, but I cannot find a property for the date that the password expires.
这怎么办?
推荐答案
这是我能想到的最简单的方法。 ..
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);
注意#1: ActiveDs
在添加引用对话框的 COM 选项卡上列为活动DS类型库
Note #1: ActiveDs
is listed on the COM tab of the Add Reference dialog as Active DS Type Library
注#2:据我所知, PasswordExpirationDate
是UTC时间。
Note #2: As far as I can tell, the PasswordExpirationDate
is in UTC time.
这篇关于主体上下文UserPrincipal如何知道密码何时过期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文