如何获得maxpwdAge属性值在ActiveDirectory中使用C ++? [英] How to get maxpwdAge attribute value in ActiveDirectory using C++?

查看:741
本文介绍了如何获得maxpwdAge属性值在ActiveDirectory中使用C ++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与AD服务器的工作,我想在 maxpwdAge属性值...

i am working with AD Server,i want to get the maxpwdAge attribute value...

我已经尝试ADSI对于这一点,但它给出了一个问题。

i already try ADSi for that,but it gives an issue.

VARIANT var;
bsNamingContext=L"maxpwdAge";

hr = ADsGetObject(pszADsPath, IID_IADsUser, (void**) &pUser);
if(SUCCEEDED(hr))
{
VariantInit(&var);
hr = pUser->Get(bsNamingContext, &var);  
}

但是,它给了-2147463155(8000500d)错误...

but,it gives -2147463155 (8000500d) error...

但我使用 bsNamingContext = LCN; 它正确地给出了CN值...

but i am using bsNamingContext=L"cn"; it gives the CN values correctly...

任何人都可以解决这个问题?

anyone can resolve it?

推荐答案

maxpwdAge 不包括在用户/联系人/人LDAP类,所以你不能找回这种方式。

maxpwdAge is not included in user/contact/person LDAP class, so you can not retrieve it that way.

您需要从对象,而不是用户对象

You need to query it from domain object, not user object

试试这个:

Const ONE_HUNDRED_NANOSECOND = .000000100   ' .000000100 is equal to 10^-7
Const SECONDS_IN_DAY = 86400

Set objDomain = GetObject("LDAP://DC=fabrikam,DC=com")     ' LINE 4
Set objMaxPwdAge = objDomain.Get("maxPwdAge")              ' LINE 5

If objMaxPwdAge.LowPart = 0 Then
  WScript.Echo "The Maximum Password Age is set to 0 in the " & _
               "domain. Therefore, the password does not expire."
  WScript.Quit
Else
  dblMaxPwdNano = Abs(objMaxPwdAge.HighPart * 2^32 + objMaxPwdAge.LowPart)
  dblMaxPwdSecs = dblMaxPwdNano * ONE_HUNDRED_NANOSECOND   ' LINE 13
  dblMaxPwdDays = Int(dblMaxPwdSecs / SECONDS_IN_DAY)      ' LINE 14
  WScript.Echo "Maximum password age: " & dblMaxPwdDays & " days"
End If

更新:

要转换的大整数人类可读的价值使用的 IADsLargeInteger 调度接口

To convert large integer to human readable value use IADsLargeInteger dispatch interface

注1 :例子是在VB,但你可以很容易地重写,因为COM吧,

Note 1 : Example is in VB, but you can easily rewrite it, because of COM.

注2 :maxpwdAge是不是每个用户配置的,但每个域(直至细粒度密码策略已启用)

Note 2 : maxpwdAge is not configured per user, but per domain (until fine-grained password policies are enabled)

进一步阅读:

  • http://msdn.microsoft.com/en-us/library/ms974598.aspx [Recommended]
  • http://msdn.microsoft.com/en-us/library/cc220201%28prot.20%29.aspx
  • http://ldapwiki.willeke.com/wiki/AD%20Determining%20Password%20Expiration
  • http://ldapwiki.willeke.com/wiki/Domain%20Wide%20Account%20Policies

这篇关于如何获得maxpwdAge属性值在ActiveDirectory中使用C ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆