开发者

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

开发者 https://www.devze.com 2023-02-21 02:18 出处:网络
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 can

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号