System Idle Value cannot be calculated in Windows 7 using window service in C #

I used the code mentioned here to calculate the system downtime through the window service. But on Windows 7 and Vista, I always get LastInputInfo.dwTimeas zero by which I cannot calculate the system downtime. I gave an example code 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 one dwTime. I need to have the correct one dwTimein my service to calculate the correct system downtime.

Please help with some examples.

+5
source share
1 answer

, GetLastInputInfo Windows Windows 7. , Vista .

: 0 Windows Vista Longhorn Server

+2

All Articles