CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2000
    Location
    Ireland
    Posts
    275

    usri3_last_logon

    Hello..
    Anybody know how I can convert

    _USER_INFO_3 info;
    info.usri3_last_logon;



    into a readable time/date??
    Any suggestions would be appreciated...

    "Help comes in the form of a ray of light"

  2. #2
    Join Date
    Oct 1999
    Location
    Broomfield, CO
    Posts
    3,382

    Re: usri3_last_logon

    usri3_last_logon and usri3_last_logoff are stored in the same format as time_t, and the Platform SDK says this about converting a time_t value:

    "Converting a time_t Value to a File Time

    The time functions included in the C run-time use the time_t type to represent the number of seconds elapsed since midnight, January 1, 1970. The following example converts a time_t value to a file time, using the Int32x32To64 function.

    void TimetToFileTime( time_t t, LPFILETIME pft )
    {
    LONGLONG ll = Int32x32To64(t, 10000000) + 116444736000000000;
    pft->dwLowDateTime = (DWORD) ll;
    pft->dwHighDateTime = ll >>32;
    }

    After you have obtained a file time, you can convert this value to system time using the FileTimeToSystemTime function. "


  3. #3
    Join Date
    Sep 2000
    Location
    Ireland
    Posts
    275

    Re: usri3_last_logon

    hi Bob..thanks for the response..
    From what I can see the usri3_last_logon is a DWORD and is not a time_t variable..
    What I am trying to do is to display Day/Month/Year/Time user last logged on..I know I need to "subtract" from the 01/00/70 00:00:00 but I have never done this before any suggestions?

    "Help comes in the form of a ray of light"

  4. #4
    Join Date
    Oct 1999
    Location
    Broomfield, CO
    Posts
    3,382

    Re: usri3_last_logon

    time_t and DWORD are both defined as long (technically, one is long, the other is unsigned long), which is why the time_t conversion I mentioned earlier works.

    Here is some sample code. If you run this, note that the time is off by the number of hours your location is offset from Coordinated Universal Time. In my case, Denver, CO is 7 hours different, so the time is 7 hours ahead of the actual local time. Use GetTimeZoneInformation() to adjust this UTC value by the bias returned in the TIME_ZONE_INFORMATION structure if you don't want to see UTC time.


    LPUSER_INFO_3 pBuff = NULL;
    NET_API_STATUS nas = NetUserGetInfo(L"\\\\VENUS", L"bclarke", 3, (LPBYTE*) &pBuff);
    if(nas == NERR_Success)
    {
    CString msg("");
    CString s;
    if(pBuff)
    {
    if(pBuff->usri3_priv == USER_PRIV_GUEST)
    msg = "User is a guest user";
    if(pBuff->usri3_priv == USER_PRIV_USER)
    msg = "User is a regular user";
    if(pBuff->usri3_priv == USER_PRIV_ADMIN)
    msg = "User has admin privileges";
     
    // convert the last logon time
    FILETIME ft;
    LONGLONG ll = Int32x32To64(pBuff->usri3_last_logon, 10000000) + 116444736000000000;
    ft.dwLowDateTime = (DWORD) ll;
    ft.dwHighDateTime = ll >>32;
    SYSTEMTIME st;
    FileTimeToSystemTime(&ft, &st);
    msg += ", last logon time was (YYYYMMDD HH:MM:SS) ";

    char pI2A[5];

    itoa(st.wYear, pI2A, 10);
    msg += pI2A;

    itoa(st.wMonth, pI2A, 10);
    s = pI2A;
    if(s.GetLength() == 1)
    s = "0" + s;
    msg += s;

    itoa(st.wDay, pI2A, 10);
    s = pI2A;
    if(s.GetLength() == 1)
    s = "0" + s;
    msg += s + " ";

    itoa(st.wHour, pI2A, 10);
    s = pI2A;
    if(s.GetLength() == 1)
    s = "0" + s;
    msg += s + ":";

    itoa(st.wMinute, pI2A, 10);
    s = pI2A;
    if(s.GetLength() == 1)
    s = "0" + s;
    msg += s + ":";

    itoa(st.wSecond, pI2A, 10);
    s = pI2A;
    if(s.GetLength() == 1)
    s = "0" + s;
    msg += s;

    ::MessageBox(m_hWnd, (LPCTSTR)msg, "NetUserGetInfo()",
    MB_OK | MB_ICONINFORMATION);
    }
    }
    else
    ::MessageBox(m_hWnd, "NetUserGetInfo() failed.", "Error", MB_OK);






Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured