The GetLastInputInfo API does not work if the windows are set to Auto Sign In,

I use the Windows API call for GetLastInputInfo to determine if the system is in standby mode. This works in almost any scenario, except when windows are set to automatically bypass the username and password and log into the system.

In this case, the GetLastInputInfo request always returns 0. I have normal conditions, it will return the tick counter of the system when the last login occurred.

Does anyone know why? Or does anyone know an alternative method to determine if a Windows session is idle?

EDIT

This is how code is written to determine the current system downtime. Detection occurs by timer and no matter how long the timer works, GetLastInputInfo will always return 0, while windows is set to "automatic login".

        long lastInputTicks = 0;
        long idleTicks = 0;

        LASTINPUTINFO lastInputInfo = new LASTINPUTINFO();
        lastInputInfo.cbSize = (uint)Marshal.SizeOf(lastInputInfo);
        lastInputInfo.dwTime = 0;

        if (GetLastInputInfo(ref lastInputInfo)) {
            lastInputTicks = lastInputInfo.dwTime;

            var systemUptime = GetTickCount();

            idleTicks = systemUptime - lastInputTicks;
        }

        return new TimeSpan(0, 0, (int)(idleTicks / 1000));

thank

UPDATE

I confirmed that this only happens because the code is running in the service.

To clarify: in a normal scenario, when automatic login is not used, the user logs in to the console, and the above code - even if it works as a service - returns the correct time of user inactivity.

, , Windows NOT. , , " " - , .

, , .

+3
1

0 , GetLastInput() FALSE. . , . GetLastInput() - FALSE (, ), FALSE .

, , Windows, . . , , , "". , , XP, Vista Windows 7. " 0" Windows.

+4

All Articles