ActiveDirectoryUserPasswordExpirationDate.NET/OUGroupPolicy在网站上搜索相关资料发现:ASP.NETC#ActiveDirectory-查看用户密码过期前的时间这说明了如何根据域策略获取密码过期时间的值。我的问题是:如果用户的OU组策略具有不同的MaxPasswordAge值,覆盖域组策略中指定的值怎么办?如何以编程方式获取OU的组策略对象?编辑:我正在添加此编辑以使问题更清楚。我所追求的是能够判断用户密码何时过期。据我所知,日期值可以由域本地策略或组对象策略控制。我有一个将Linq转换为Ldap查询的Linq2DirectoryServiceProvider。因此,获取日期到期值的LDAP查询对于此主题是最佳的。如果您回答包含.net支持的包装器的对象包含在这个等式中-这将是一个死答案!让我从具有VisualBasic和VBScript示例的http://support.microsoft.com/kb/323750和http://www.anitkb.com/2010/03/how-to-implement-active-directory开始。html概述了maxPwdAgeOU设置如何影响计算机,而不是用户。它还有一个注释指向AloInfo.exe作为MS的一个工具,可用于获取密码期限。这是一个例子:usingSystem;使用System.Collections.Generic;使用System.Linq;使用系统文本;使用System.DirectoryServices;命名空间LDAP{类程序{staticvoidMain(string[]args){stringdomainAndUsername=string.Empty;字符串域=string.Empty;字符串用户名=string.Empty;字符串密码=string.Empty;AuthenticationTypesat=AuthenticationTypes.Anonymous;StringBuildersb=newStringBuilder();域=@"LDAP://wxyz";domainAndUsername=@"LDAP://wxyz/cn=LawrenceE."+"Smithmier,Jr.,cn=Users,dc=corp,"+"dc=productiveedge,dc=com";userName="管理员";passWord="xxxpasswordxxx";在=AuthenticationTypes.Secure;DirectoryEntryentry=newDirectoryEntry(domain,userName,passWord,at);DirectorySearchermySearcher=newDirectorySearcher(条目);SearchResult收集结果;字符串过滤器="maxPwdAge=*";mySearcher.Filter=过滤器;结果=mySearcher.FindAll();长最大天数=0;if(results.Count>=1){在t64maxPwdAge=(Int64)结果[0].Properties["maxPwdAge"][0];maxDays=maxPwdAge/-864000000000;}DirectoryEntryentryUser=newDirectoryEntry(domainAndUsername,userName,passWord,atUser);mySearcher=newDirectorySearcher(入口);结果=mySearcher.FindAll();漫长的日子Left=0;如果(results.Count>=1){varlastChanged=results[0].Properties["pwdLastSet"][0];daysLeft=maxDays-DateTime.Today.Subtract(DateTime.FromFileTime((long)lastChanged)).Days;}Console.WriteLine(String.Format("您必须在"+"{0}天内",daysLeft));控制台.ReadLine();}}}下面的代码让我可以获取域和本地用户帐户的密码到期日期:+'/'+userId+",user")){return(DateTime)userEntry.InvokeGet("PasswordExpirationDate");使用publicstaticDateTimeGetPasswordExpirationDat获取帐户的到期日期e(stringuserId){stringforestGc=String.Format("GC://{0}",Forest.GetCurrentForest().Name);varsearcher=newDirectorySearcher();searcher=newDirectorySearcher(newDirectoryEntry(forestGc));searcher.Filter="(sAMAccountName="+userId+")";varresults=searcher.FindOne().GetDirectoryEntry();返回(DateTime)results.InvokeGet("PasswordExpirationDate");以前的一些答案依赖于关于DirectoryEntry.InvokeGet方法,MS说不应该使用它,所以这是另一种方法:publicstaticDateTimeGetPasswordExpirationDate(UserPrincipaluser){ActiveDs.IADsUsernativeDeUser=(ActiveDs.IADsUser)deUser.NativeObject;返回nativeDeUser.PasswordExpirationDate;您需要添加对通常位于C:\Windows\System32\activeds.tlb中的ActiveDSCOM库的引用。以上就是C#学习教程的全部内容:ActiveDirectory用户密码有效期。NET/OU组策略。如果对你有用,需要了解更多C#学习教程,希望大家多加关注——本文来自网络合集,不代表立场,如涉及侵权,请点击右转联系管理员删除。如需转载请注明出处:
