Moment when all interactive user accounts have been logged out
I'm writing a Windows service using WinAPIs and C++. One of the options is that I need to send the system into sleep after all users are logged out. The log-out command is started from the UI (which can notify my service), the problem is knowing how long it takes for all user accounts to be completely logged out before putting the system to sleep.
I first thought to introduce an artificial delay from the moment when the log-out command is issued and before entering the sleep mode, but in a situation when some user account was configured with a roaming profile, the log-out process may well exceed my delay.
So any suggestions how to know if all user accounts are logged out "for sure"?
Re: Moment when all interactive user accounts have been logged out
This may be of help. It provides info about all users currently logged on.
http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
Re: Moment when all interactive user accounts have been logged out
Quote:
Originally Posted by
2kaud
If this api is used, be sure to read the remarks section with regard to services impersonating users.
Re: Moment when all interactive user accounts have been logged out
@2kaud: Thanks for the link.
@Arjay: Thank you for the heads-up. So is there a way to see if the entry returned is from a service doing the impersonation or if it is from an actual interactive user?
Re: Moment when all interactive user accounts have been logged out
Quote:
Originally Posted by
dc_2000
@Arjay: Thank you for the heads-up. So is there a way to see if the entry returned is from a service doing the impersonation or if it is from an actual interactive user?
I don't know offhand. Try info level 1 with a service that is started under a user account and compare it with a service started under a local service account. You might have to use other apis to walk the running service processes to retrieve the user they are running under.
Re: Moment when all interactive user accounts have been logged out
EnumServicesStatusEx()
http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
provides some info about all the services installed on the system. Unfortunately, it doesn't provide the name of the account under which the services are running. To get this info you use
QueryServiceConfig() for a specified service
http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
and lpServiceStartName in the QUERY_SERVICE_CONFIG structure contains the service logon account name.
http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
Re: Moment when all interactive user accounts have been logged out
No, I think I'm about to abandon NetWkstaUserEnum. I'm not sure what accounts it reports on, but it doesn't do what I need -- list of currently logged on interactive users. For instance it keeps returning a user account that was already logged off.
Re: Moment when all interactive user accounts have been logged out
Quote:
Originally Posted by
dc_2000
No, I think I'm about to abandon NetWkstaUserEnum. I'm not sure what accounts it reports on, but it doesn't do what I need -- list of currently logged on interactive users. For instance it keeps returning a user account that was already logged off.
What level are you calling it with and how are you calling it? Are you using NetApiFreeBuffer after each call?
Re: Moment when all interactive user accounts have been logged out
I'm calling it with level 1 using the example from this page.
Re: Moment when all interactive user accounts have been logged out
Quote:
Originally Posted by
dc_2000
I'm calling it with level 1 using the example from
this page.
Try it with level 1.
Re: Moment when all interactive user accounts have been logged out
Perhaps a bit late, but have a look at
LsaEnumerateLogonSessions()
http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
together with
LsaGetLogonSessionData()
http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
These can be used to retrieve the logon details of the users - including the type of logon, the user name and the name of the domain used to authenticate.
When calling from a service, I think it only returns info about currently logged on users.