I have used the code mentioned here to calculate the system Idle time through a window service. But in window开发者_JAVA技巧s 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
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
精彩评论