How to get User Login and logout time in C++ / MFC .?
-
Hi, I have one query. I want to get the Login and Logout Time of a user. I want to get the time when user login to a pc, lock the PC, Logout (shutdown) the PC. I want to keep track of the Login / logout / Locking time of the user. Is there any class or any code available in C++ / MFC. Any help will be appreciated. Regards,
-
Hi, I have one query. I want to get the Login and Logout Time of a user. I want to get the time when user login to a pc, lock the PC, Logout (shutdown) the PC. I want to keep track of the Login / logout / Locking time of the user. Is there any class or any code available in C++ / MFC. Any help will be appreciated. Regards,
You can use the Windows Event Log API[^]. Example code: http://orithena.cas.msu.edu/wiki/index.php/Windows_API_Example_Event_Log_Reading_C%2B%2B_Code[^]. Note that accessing event logs requires administrator privileges.
-
Hi, I have one query. I want to get the Login and Logout Time of a user. I want to get the time when user login to a pc, lock the PC, Logout (shutdown) the PC. I want to keep track of the Login / logout / Locking time of the user. Is there any class or any code available in C++ / MFC. Any help will be appreciated. Regards,
mbatra31 wrote:
I have one query. I want to get the Login and Logout Time of a user.
Have you considered using
NetUserGetInfo()
withUSER_INFO_2
? It has ausri2_last_logon
andusri2_last_logon
field."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
mbatra31 wrote:
I have one query. I want to get the Login and Logout Time of a user.
Have you considered using
NetUserGetInfo()
withUSER_INFO_2
? It has ausri2_last_logon
andusri2_last_logon
field."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
Hello David, Thanks for sharing the info. It was very helpful. I have one query again. this function gives the Last logon and Logoff time in the number of seconds that have elapsed since 00:00:00, January 1, 1970, GMT. How can I get the correct value in Time format. Also I want to get the record of user logon and logoff time for each day. Should I use the same function.? Regards,
-
Hello David, Thanks for sharing the info. It was very helpful. I have one query again. this function gives the Last logon and Logoff time in the number of seconds that have elapsed since 00:00:00, January 1, 1970, GMT. How can I get the correct value in Time format. Also I want to get the record of user logon and logoff time for each day. Should I use the same function.? Regards,
-
Hello David, Thanks for sharing the info. It was very helpful. I have one query again. this function gives the Last logon and Logoff time in the number of seconds that have elapsed since 00:00:00, January 1, 1970, GMT. How can I get the correct value in Time format. Also I want to get the record of user logon and logoff time for each day. Should I use the same function.? Regards,
mbatra31 wrote:
I have one query again. this function gives the Last logon and Logoff time in the number of seconds that have elapsed since 00:00:00, January 1, 1970, GMT. How can I get the correct value in Time format.
Converting time since that epoch was something I learned very early on in my career (some 25 years ago). It's worth the effort at figuring it out (without the help of Google).
mbatra31 wrote:
Also I want to get the record of user logon and logoff time for each day. Should I use the same function.?
Since the above is always referenced from a fixed point in time, you'd need to "capture" it once per day. Admittedly, there may be a log somewhere that Windows keeps where it writes an entry for every time a user logs in/out of a workstation. I've never had the need to know so I can't tell you if this is true or not.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles