SystemParametersInfo and ERROR_OPERATION_IN_PROGRESS

893 views Asked by At

I'm coding this user-mode executable that can be run from a local service on a Windows platform in a context of logged in users. Its main purpose is to configure a desktop of all logged in users. It calls the following API to set up screensaver:

if(!SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, nTimeoutSec, 0, 0))
{
    //Error
    GetLastError();
}

if(!SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, nActive, 0, 0))
{
    //Error
    GetLastError();
}

The code above works in most cases, except at times when I have more than one user logged on to the Windows console I get this weird error ERROR_OPERATION_IN_PROGRESS. I looked up the documentation and it has this explanation:

If the machine has entered power saving mode or system lock state, an ERROR_OPERATION_IN_PROGRESS exception occurs.

OK, but how shall I treat this error?

PS. This happens most often on Windows 8.

2

There are 2 answers

1
kain64b On

SPI_SETSCREENSAVEACTIVE can produce some error and do nothing. Try to send a WM_SYSCOMMAND with SC_SCREENSAVE message to the GetDesktopWindow() window.

0
AhmedBM On

Ok so it looks like this is actually not possible with Windows 8+, although its not explicitly stated on MSDN.

My Research

It does state on another MSDN article for SetThreadExecutionState that on Windows 8 the ES_DISPLAY_REQUIRED flag does not wake the screen.

Windows 8: This flag can only keep a display turned on, it can't turn on a display that's currently off.

There is an API call for removing the active screensaver (SPI_SETSCREENSAVEACTIVE) does state the following:

If the machine has entered power saving mode or system lock state, an ERROR_OPERATION_IN_PROGRESS exception occurs

Conclusion

The system was not in a lock state AND not in power saving mode (using GUID_MIN_POWER_SAVINGS), so it seems Windows 8+ machines cannot wake the screen.