I have used the code mentioned here to calculate the system Idle time through a window service. But in windows 7 & Vista I always get the LastInputInfo.dwTime
as zero by which I cannot calculate the system idle time. I have given the code sample below.
// If we have a value from the function
if (GetLastInputInfo(ref LastInputInfo))
{
// Get the number of ticks at the point when the last activity was seen
LastInputTicks = (int)LastInputInfo.dwTime;
// Number of idle ticks = system uptime ticks - number of ticks at last input
IdleTicks = systemUptime - LastInputTicks;
}
When I test the same code in a windows application I get the correct dwTime
. I need to have the correct dwTime
in my service to calculate correct idle time of the system.
Please help with some examples