Click here to Skip to main content
15,569,644 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Regarding Constructor Calling in C++ Pin
CPallini16-Jun-21 0:39
mveCPallini16-Jun-21 0:39 
QuestionAdvice on writing a GUI application that can run on very old Windows operating systems without Service Packs and Frameworks Pin
arnold_w14-Jun-21 9:32
arnold_w14-Jun-21 9:32 
AnswerRe: Advice on writing a GUI application that can run on very old Windows operating systems without Service Packs and Frameworks Pin
Victor Nijegorodov14-Jun-21 9:43
Victor Nijegorodov14-Jun-21 9:43 
AnswerRe: Advice on writing a GUI application that can run on very old Windows operating systems without Service Packs and Frameworks Pin
Mircea Neacsu14-Jun-21 9:45
Mircea Neacsu14-Jun-21 9:45 
AnswerRe: Advice on writing a GUI application that can run on very old Windows operating systems without Service Packs and Frameworks Pin
Richard MacCutchan14-Jun-21 9:51
mveRichard MacCutchan14-Jun-21 9:51 
AnswerRe: Advice on writing a GUI application that can run on very old Windows operating systems without Service Packs and Frameworks Pin
Eddy Vluggen14-Jun-21 10:18
professionalEddy Vluggen14-Jun-21 10:18 
AnswerRe: Advice on writing a GUI application that can run on very old Windows operating systems without Service Packs and Frameworks Pin
Maximilien15-Jun-21 6:22
Maximilien15-Jun-21 6:22 
QuestionWindows 10 - find last logon time in C++ ?? Pin
Derell Licht5-Jun-21 17:28
professionalDerell Licht5-Jun-21 17:28 
I'm trying to determine this value for a system-status program that I maintain.
In the past, I've just shown Uptime, but now that I'm forced to Windows 10, that isn't entirely informative!! If I log out of my machine (shutdown -l) and then log back in, Uptime doesn't get reset. So I want to add an option to show logon time vs reboot time (Uptime)... but I'm not having much success with this...

I have found several articles which recommend NetUserGetInfo(), but this is returning invalid data for me... for example, I just logged out, and back in, to my machine... here is the code, followed by the results that I get:

// Call the NetUserGetInfo function.
    dwLevel = 2;
    wchar_t username[UNLEN+1];
    DWORD username_len = UNLEN+1;
    GetUserNameW(username, &username_len);
    nStatus = NetUserGetInfo(NULL, username, dwLevel, (LPBYTE *) & pBuf);
    //  skipping result checking
    pBuf2 = (LPUSER_INFO_2) pBuf;
    wprintf(L"User account name: %s\n", pBuf2->usri2_name);
    wprintf(L"Password age (seconds): %d\n", pBuf2->usri2_password_age);
    wprintf(L"Last logon (seconds since January 1, 1970 GMT): %d\n", pBuf2->usri2_last_logon);
    time_t logon_time = pBuf2->usri2_last_logon ;
    char buff[20];
    strftime(buff, 20, "%Y-%m-%d %H:%M:%S", localtime(&logon_time));
    printf("logon time: %s\n", buff);

The results that I get are:
User account name: dan7m
Password age (seconds): 10221317
Last logon (seconds since January 1, 1970 GMT): 1616249786
logon time: 2021-03-20 07:16:26

Note that the logon time *actually* around 1920 on 06/05/21...

So I have two questions, I guess...
1. is there some way to make this function actually work??
2. if not, how else can I programmatically access the login time on Windows 10 64bit??
QuestionRe: Windows 10 - find last logon time in C++ ?? Pin
David Crow5-Jun-21 17:53
David Crow5-Jun-21 17:53 
AnswerRe: Windows 10 - find last logon time in C++ ?? Pin
Derell Licht5-Jun-21 18:06
professionalDerell Licht5-Jun-21 18:06 
AnswerRe: Windows 10 - find last logon time in C++ ?? Pin
Derell Licht5-Jun-21 18:11
professionalDerell Licht5-Jun-21 18:11 
AnswerRe: Windows 10 - find last logon time in C++ ?? Pin
Randor 6-Jun-21 6:21
professional Randor 6-Jun-21 6:21 
GeneralRe: Windows 10 - find last logon time in C++ ?? Pin
Derell Licht6-Jun-21 7:27
professionalDerell Licht6-Jun-21 7:27 
GeneralRe: Windows 10 - find last logon time in C++ ?? Pin
Randor 6-Jun-21 8:26
professional Randor 6-Jun-21 8:26 
GeneralRe: Windows 10 - find last logon time in C++ ?? Pin
Derell Licht6-Jun-21 8:44
professionalDerell Licht6-Jun-21 8:44 
GeneralRe: Windows 10 - find last logon time in C++ ?? Pin
Randor 6-Jun-21 9:11
professional Randor 6-Jun-21 9:11 
AnswerRe: Windows 10 - find last logon time in C++ ?? Pin
Derell Licht6-Jun-21 16:20
professionalDerell Licht6-Jun-21 16:20 
GeneralRe: Windows 10 - find last logon time in C++ ?? Pin
Richard MacCutchan6-Jun-21 22:16
mveRichard MacCutchan6-Jun-21 22:16 
GeneralRe: Windows 10 - find last logon time in C++ ?? Pin
Derell Licht7-Jun-21 4:14
professionalDerell Licht7-Jun-21 4:14 
GeneralRe: Windows 10 - find last logon time in C++ ?? Pin
Maximilien7-Jun-21 10:15
Maximilien7-Jun-21 10:15 
Questionurgent question Pin
MAHMOUD ALI Jun20215-Jun-21 2:03
MAHMOUD ALI Jun20215-Jun-21 2:03 
AnswerRe: urgent question Pin
Victor Nijegorodov5-Jun-21 2:24
Victor Nijegorodov5-Jun-21 2:24 
GeneralRe: urgent question Pin
MAHMOUD ALI Jun20215-Jun-21 2:37
MAHMOUD ALI Jun20215-Jun-21 2:37 
GeneralRe: urgent question Pin
Victor Nijegorodov5-Jun-21 2:41
Victor Nijegorodov5-Jun-21 2:41 
AnswerRe: urgent question Pin
Richard MacCutchan5-Jun-21 3:20
mveRichard MacCutchan5-Jun-21 3:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.