user779777
user779777

Reputation: 53

Determine if there is any interactive user on a Windows 7 machine

From a service running on a Windows 7 machine, I'd like to be able to determine if there is any interactive user logged on AND active. This should count for users that are logged on locally or via remote-desktop. If a user is logged on locally and locks their machine, that would be considered inactive.

Upvotes: 1

Views: 749

Answers (1)

David Heffernan
David Heffernan

Reputation: 612794

  • Enumerate the sessions with WTSEnumerateSessions. This gives you a list of session IDs.
  • Call WTSQuerySessionInformation for each session ID. Specify WTSSessionInfoEx for the WTSInfoClass parameter. This gives you a WTSINFOEX struct.
  • Inside that is a WTSINFOEX_LEVEL1 struct. From that you can read the session state and check for the session being locked by looking for WTS_SESSIONSTATE_LOCK in the session flags.

Upvotes: 1

Related Questions