is it possible to get user’s login and logout time in a objective-c program? I can get the session ID, username, userUID, userIsActive and loginCompleted with CGSessionCopyCurrentDictionary function but I can’t get login and logout time from it, can I?
I know I can get the info from console.app, but I would like to put it in a program.
Where do I look for more info on that? Can’t find it in Development guide from Apple.
Thanks!
I don’t know if there are any special Cocoa function to get user login/logout time.
But you can read the login/logout history directly, using
getutxent_wtmp(). This is what the “last” command line tool does, as can be seen in the source code: http://www.opensource.apple.com/source/adv_cmds/adv_cmds-149/last/last.cJust to give a very simple example: The following program prints all login/logout times to the standard output:
And just for fun: A Swift 4 solution: