log for user login info

Hi, I would like to have a program on my PC which records the login and logout times for different users. How easy writing this would be. How do I begin?

Thanks
From the top of my head you need a Windows service, so start reading about creating a service in C/C++. There are some special considerations in order to properly interact with the Service Manager.

After that you'll get notifications for user log on and log off in an extended handler callback function that you register using RegisterServiceCtrlHandlerEx() (http://msdn.microsoft.com/en-us/library/windows/desktop/ms685058(v=vs.85).aspx ). This handler will receive logon/logoff notifications as shown here http://msdn.microsoft.com/en-us/library/windows/desktop/ms683241(v=vs.85).aspx .

The handler above will get the session ID, and you can use it in a call to WTSQueryUserToken() (http://msdn.microsoft.com/en-us/library/windows/desktop/aa383840(v=vs.85).aspx ) to obtain the logged-on user token, but bear in mind that this function only works if the service is running under NT AUTHORITY\SYSTEM. Finally, you can query the token to obtain the user's information.
Topic archived. No new replies allowed.