'Is it possible to know last user activity from a Windows service?
I have a Windows service program (written using C++) that is required to perform an energy saving power operation at a certain time of the day. I need to find out if a user might be at the terminal at the time when the power operation is performed and if he/she is, postpone it then. So my question is, how do you know the moment of the last user activity from a Windows service (running as a local system)?
PS. By user activity I mean keyboard and mouse activity.
Solution 1:[1]
Depending on how deterministic it has to be, you could use the task scheduler. It can trigger the task when the computer is idle, wait for a while for it to be, etc. You can add the task manually to begin, then use the API.

Solution 2:[2]
In a rare case of Microsoft actually providing the API function that you need, you can use GetLastInputInfo().
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ixe013 |
| Solution 2 | Greg Wittmeyer |
