Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 924
deepu Avatar asked Nov 05 '22 00:11

deepu


1 Answers

I dont think you will be able to use GetLastInputInfo in windows service on Windows 7. This is not about the code, It's about service hardening in Vista and later.

Read this: Services isolation in Session 0 of Windows Vista and Longhorn Server

like image 96
HABJAN Avatar answered Nov 09 '22 16:11

HABJAN