Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to get User Login and logout time in C++ / MFC .?

How to get User Login and logout time in C++ / MFC .?

Scheduled Pinned Locked Moved C / C++ / MFC
c++databasehelptutorialquestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mbatra31
    wrote on last edited by
    #1

    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,

    J D 2 Replies Last reply
    0
    • M mbatra31

      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,

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • M mbatra31

        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,

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        mbatra31 wrote:

        I have one query. I want to get the Login and Logout Time of a user.

        Have you considered using NetUserGetInfo() with USER_INFO_2? It has a usri2_last_logon and usri2_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

        M 1 Reply Last reply
        0
        • D David Crow

          mbatra31 wrote:

          I have one query. I want to get the Login and Logout Time of a user.

          Have you considered using NetUserGetInfo() with USER_INFO_2? It has a usri2_last_logon and usri2_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

          M Offline
          M Offline
          mbatra31
          wrote on last edited by
          #4

          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,

          F D 2 Replies Last reply
          0
          • M mbatra31

            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,

            F Offline
            F Offline
            Frankie C
            wrote on last edited by
            #5

            This is Unix time (UTC) use the time functions. For an example see[^].

            1 Reply Last reply
            0
            • M mbatra31

              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,

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups