简体   繁体   中英

How to check the time that user has logged in to Windows?

I want to solve the following problem:

My C++ program starts up automatically on user login, but the program depends on some services which are not started for several minutes on very slow computers (happens often) and does not work correctly.

  • If it does not work correctly I want to show the user a notification that he has to wait a bit more before he can start working, but after a few minutes,
  • If the program still does not work (happens often), it has to show warning message - something is wrong and user interaction is needed.

I saw an entry (Winlogon) in the event viewer, but the user is SYSTEM and I want to know for the specific user that uses my program.

Is there some simple way to check when a user that started my program has logged in?

When your program runs as part of user login, it will not run before that user has logged in.

The proper solution here is to check whether the dependencies have started. Using the Service Control Manager ( OpenSCManager ), query each service state ( QueryServiceStatusEx ). There's a difference between states starting and started ; you need the latter.

You can use NetGetUserInfo() to get information about an user account. Last logon time is in the USER_INFO_2 structure.

When the first parameter is NULL, the function refers to users on the local computer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM