我想使用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).
更多推荐
发布评论