1

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.

ahmd0
  • 16,633
  • 33
  • 137
  • 233

2 Answers2

0

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

Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
kain64b
  • 2,258
  • 2
  • 15
  • 27
  • Thanks for the suggestion, but at this point I can't emulate that condition... Any idea when exactly that error is returned? – ahmd0 Aug 13 '12 at 08:45
0

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.

AhmedBM
  • 1,202
  • 17
  • 15