win7,如何获取当前用户的登录时间?

编程入门 行业动态 更新时间:2024-10-23 17:23:50
本文介绍了win7,如何获取当前用户的登录时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

嗨。 i希望得到当前用户登录系统的时间。 i use IADsUser :: get_LastLogin(),但ADsGetObject返回错误代码。 i从本网站下载的演示中找到代码,我的操作系统是win7。

hi. i want to get the time when the current user login system. i use IADsUser::get_LastLogin(),but the ADsGetObject return a error code. i find the code from a demo that download from this Website,and My operating system is win7.

IADsWinNTSystemInfo *pNTsys; HRESULT hr = CoCreateInstance(CLSID_WinNTSystemInfo, NULL, CLSCTX_INPROC_SERVER, IID_IADsWinNTSystemInfo, (void**)&pNTsys); pNTsys->AddRef(); BSTR bstrCompName; pNTsys->get_ComputerName(&bstrCompName); CString cscompName=bstrCompName; SysFreeString(bstrCompName); BSTR bstrDomainName; pNTsys->get_DomainName(&bstrDomainName); CString CSDomainName=bstrDomainName; SysFreeString(bstrDomainName); pNTsys->Release(); //From ADSPath ADSPath.Format("WinNT://%s/%s",CSDomainName,cscompName); //Get the container object //*****************here get error code group not be found hr=ADsGetObject(ADSPath.AllocSysString(),IID_IADsContainer,(void **)&pUsers);

推荐答案

我认为AD的东西只适用于域控制器(?)。 这是我用于登录时的一些代码的摘录(对不起,如果它有语法错误就编译而不编译): I think the AD stuff is only for use on a domain controller (?). Here is an extract of some code I use for login time (sorry it is editted without compile if it has syntax errors): #include <Ntsecapi.h> // [link to secur32.lib] BOOL GetLogonLUID (LUID *pLuid) { BOOL bSuccess = FALSE; HANDLE hThread = NULL; TOKEN_STATISTICS ts = {0}; DWORD cbReturnLength = sizeof(TOKEN_STATISTICS); bSuccess = OpenProcessToken (GetCurrentProcess(), TOKEN_QUERY, &hThread); if (bSuccess) { bSuccess = GetTokenInformation (hThread, TokenStatistics, &ts, sizeof(TOKEN_STATISTICS), &cbReturnLength); if (bSuccess) *pLuid = ts.AuthenticationId; } if (hThread) CloseHandle (hThread); return bSuccess; } SYSTEMTIME& GetLoginTime() { static SYSTEMTIME st = {0}; FILETIME ft = {0}; LUID LogonLuid = {0}; PSECURITY_LOGON_SESSION_DATA pLogonSessionData = NULL; GetLogonLUID (&LogonLuid); NTSTATUS ntStatus = LsaGetLogonSessionData (&LogonLuid, &pLogonSessionData); if (ntStatus == 0) { if (pLogonSessionData->LogonTime.QuadPart) { FileTimeToLocalFileTime ((const FILETIME *)&pLogonSessionData->LogonTime, &ft); FileTimeToSystemTime (&ft, &st); } } if (pLogonSessionData) LsaFreeReturnBuffer(pLogonSessionData); return st; }

更多推荐

win7,如何获取当前用户的登录时间?

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

发布评论

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

>www.elefans.com

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