使用c ++的密码到期日期?(Password Expiry Date using c++?)

编程入门 行业动态 更新时间:2024-10-26 22:25:06
使用c ++的密码到期日期?(Password Expiry Date using c++?)

我想使用c ++ win32 API显示密码​​到期对话框...

我使用System.directoryservice命名空间完成它...

但现在我需要Win32 API ..

有任何功能获取密码到期日期?

提前致谢

i want to display the password expiry dialogbox using c++ win32 API...

i done it using System.directoryservice namespace...

But now i need in Win32 API..

Any functions there for get password expiry date?

Thanks in advance

最满意答案

您可以使用以下函数来获取密码到期日期:

HRESULT GetPasswordExpirationDate(LPTSTR lpszPathName, LPSYSTEMTIME lpExpirationDate) { HRESULT hr; IADsUser *pUser; hr = ADsGetObject(lpszPathName, IID_IADsUser, (void**) &pUser); if(SUCCEEDED(hr)) { DATE expirationDate; hr = pUser->get_PasswordExpirationDate(&expirationDate); if (SUCCEEDED(hr)) VariantTimeToSystemTime(expirationDate, lpExpirationDate); pUser->Release(); } return hr; }

其中lpszPathName是LDAP或WinNT路径, lpExpirationDate是指向SYSTEMTIME结构的指针。

请注意,您必须包含Windows.h , Iads.h和Adshlp.h并与ADSIid.Lib和ActiveDS.Lib链接才能使其正常工作。

用法示例:

CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); SYSTEMTIME expirationDate; HRESULT hr = GetPasswordExpirationDate(_T("WinNT://ComputerName/UserName,user"), &expirationDate); if (SUCCEEDED(hr)) { //TODO: do whatever you want with the expirationDate here } CoUninitialize();

您可能希望使用以下API调用之一来检索当前用户和计算机/域名: GetUserName , GetComputerName GetUserNameEx , NetWkstaUserGetInfo

如果需要检索多个域用户的密码到期日期,最好使用ADsBuildEnumerator而不是ADsGetObject (请参阅MSDN上的示例)。

You can use the following function to get the password expiration date:

HRESULT GetPasswordExpirationDate(LPTSTR lpszPathName, LPSYSTEMTIME lpExpirationDate) { HRESULT hr; IADsUser *pUser; hr = ADsGetObject(lpszPathName, IID_IADsUser, (void**) &pUser); if(SUCCEEDED(hr)) { DATE expirationDate; hr = pUser->get_PasswordExpirationDate(&expirationDate); if (SUCCEEDED(hr)) VariantTimeToSystemTime(expirationDate, lpExpirationDate); pUser->Release(); } return hr; }

Where lpszPathNameis a LDAP or WinNT path and lpExpirationDate is a pointer to SYSTEMTIME structure.

Note, that you must include Windows.h, Iads.h and Adshlp.h and link with ADSIid.Lib and ActiveDS.Lib to get it work.

Example usage:

CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); SYSTEMTIME expirationDate; HRESULT hr = GetPasswordExpirationDate(_T("WinNT://ComputerName/UserName,user"), &expirationDate); if (SUCCEEDED(hr)) { //TODO: do whatever you want with the expirationDate here } CoUninitialize();

You may want to use one of the following API calls to retrieve current user and computer/domain names: GetUserName, GetComputerName GetUserNameEx, NetWkstaUserGetInfo

If you need to retrieve password expiration dates for multiple domain users, it might be better to use ADsBuildEnumerator instead of ADsGetObject (see example on MSDN).

更多推荐

本文发布于:2023-07-24 01:58:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1240172.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日期   密码   Password   Expiry   Date

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!