[英]How to get password expiry date using C++ win32 API?
I am using C++ with the win32 Api and I want to get the password expiry date for a user using ADSI.我将 C++ 与 win32 Api 一起使用,我想获取使用 ADSI 的用户的密码到期日期。
CoInitialize(NULL);
LPWSTR pszADsPath=L"LDAP://CN=arjun,CN=Users,DC=raja,DC=com";
//HRESULT hr;
IADsUser *pUser;
hr = ADsGetObject(pszADsPath, IID_IADsUser, (void**) &pUser);
if(SUCCEEDED(hr))
{
DATE expirationDate;
VariantInit(&var);
hr = pUser->get_PasswordLastChanged(&expirationDate);
hr = pUser->get_PasswordExpirationDate(&expirationDate);
if (SUCCEEDED(hr))
VariantTimeToSystemTime(expirationDate,&lpExpirationDate);
pUser->Release();
}
Calling get_PasswordLastChanged
will give success and return last changed password date, but I need the expiration date.调用get_PasswordLastChanged
会成功并返回上次更改密码的日期,但我需要到期日期。
Using get_PasswordExpirationDate
, I get S_OK
(success) but it also gives an error code of -2147463155
.使用get_PasswordExpirationDate
,我得到S_OK
(成功),但它也给出了错误代码-2147463155
。
Can anyone explain what is going wrong?谁能解释出什么问题了?
The error translates to ADS_PROPERTY_NOT_FOUND. 该错误将转换为ADS_PROPERTY_NOT_FOUND。 Could it be that the password for this user doesn't expire? 可能是该用户的密码没有过期吗?
I know this is an old post but I looked for the same thing and came upon this post and for me the OP's code (with a slight change) works.我知道这是一篇旧帖子,但我寻找同样的东西并找到了这篇帖子,对我来说,OP 的代码(略有改动)有效。 I added ldap url and using port 636. Just in case anyone searches for the same thing:我添加了 ldap url 并使用端口 636。以防万一有人搜索相同的东西:
CCoInitialize CoInitialize;
if( !CoInitialize.IsSuccessful() )
{
stringstream Text;
Text << L"CoInitialize returned <" << CoInitialize.GetMessage() << L">" << endl;
this->WriteLogThreadSafe( Text.str() );
// Continue anyway because it could be it was already initialized.
}
LPWSTR pszADsPath=L"LDAP://<YOUR LDAP SERVER>:636/<YOUR DN>";
//HRESULT hr;
IADsUser *pUser;
HRESULT hr = ADsGetObject(pszADsPath, IID_IADsUser, (void**) &pUser);
if(SUCCEEDED(hr))
{
SYSTEMTIME SystemTime = {};
DATE expirationDate = {};
VARIANTARG var = {};
VariantInit(&var);
hr = pUser->get_PasswordLastChanged(&expirationDate);
hr = pUser->get_PasswordExpirationDate(&expirationDate);
if (SUCCEEDED(hr))
VariantTimeToSystemTime( expirationDate,&SystemTime );
pUser->Release();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.