Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9152601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:05:39+00:00 2026-06-17T12:05:39+00:00

is it possible to get user’s login and logout time in a objective-c program?

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:05:41+00:00Added an answer on June 17, 2026 at 12:05 pm

    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.c

    Just to give a very simple example: The following program prints all login/logout times to the standard output:

    #include <stdio.h>
    #include <utmpx.h>
    
    int main(int argc, const char * argv[])
    {
        struct utmpx *bp;
        char *ct;
    
        setutxent_wtmp(0); // 0 = reverse chronological order
        while ((bp = getutxent_wtmp()) != NULL) {
            switch (bp->ut_type) {
                case USER_PROCESS:
                    ct = ctime(&bp->ut_tv.tv_sec);
                    printf("%s login %s", bp->ut_user, ct);
                    break;
                case DEAD_PROCESS:
                    ct = ctime(&bp->ut_tv.tv_sec);
                    printf("%s logout %s", bp->ut_user, ct);
                    break;
    
                default:
                    break;
            }
        };
        endutxent_wtmp();
    
        return 0;
    }
    

    And just for fun: A Swift 4 solution:

    import Foundation
    
    extension utmpx {
        var userName: String {
            return withUnsafePointer(to: ut_user) {
                $0.withMemoryRebound(to: UInt8.self, capacity: MemoryLayout.size(ofValue: ut_user)) {
                    String(cString: $0)
                }
            }
        }
        var timestamp: Date {
            return Date(timeIntervalSince1970: TimeInterval(ut_tv.tv_sec))
        }
    }
    
    setutxent_wtmp(0)
    while let bp = getutxent_wtmp() {
    
        switch bp.pointee.ut_type {
        case Int16(USER_PROCESS):
            print(bp.pointee.userName, "login", bp.pointee.timestamp)
        case Int16(DEAD_PROCESS):
            print(bp.pointee.userName, "logout", bp.pointee.timestamp)
        default:
            break
        }
    }
    endutxent_wtmp();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anybody know, is it possible and how can I get name of user
Possible Duplicate: username urls like twitter and facebook How to get user friendly URLs
is it possible to get the user_id from the facebook user without requiring the
Is it possible to build an iOS app that will get user's voicemails ?
Is it possible to get shutdown reason in Windows Server 2008 immediately after user
Is it possible to get design mode to work for templated user controls? I
Is it possible to get the email address which the user has entered? I
is it possible to get an valid access token for an user via a
Possible Duplicate: Facebook API - How to get user’s address, phone #? Is it
Is it possible get the last visited pages by user using C# / ASP.NET

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.