0

During the Windows login process, I try to activate the screensaver:

ret = SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, state, NULL, 0);

When I use GetLastError(), it returns 329; I found on MSDN:

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

So I change the code:

int loopNum = 10;
do{
    ret = SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, state, NULL, 0);
    if(!ret){
loginfo("[set_screensave_active] set screensave active status to 1 failed, gle = %d",Getlasterror());
}
    Sleep(1000);
}
while(loopNum--);

I'm sure that Windows login takes a short time.

This code is triggered when I login to Windows. Sometimes the error 329 is reported, all 10 times the loop fails!

The logs are as follows:

2022-03-08 08:58:33 [12120/14436] [WARN] [set_screensave_active] set screensave active status to 1 failed, gle 329

2022-03-08 08:58:34 [12120/14436] [WARN] [set_screensave_active] set screensave active status to 1 failed, gle 329

2022-03-08 08:58:35 [12120/14436] [WARN] [set_screensave_active] set screensave active status to 1 failed, gle 329

2022-03-08 08:58:36 [12120/14436] [WARN] [set_screensave_active] set screensave active status to 1 failed, gle 329

2022-03-08 08:58:37 [12120/14436] [WARN] [set_screensave_active] set screensave active status to 1 failed, gle 329

2022-03-08 08:58:38 [12120/14436] [WARN] [set_screensave_active] set screensave active status to 1 failed, gle 329

2022-03-08 08:58:39 [12120/14436] [WARN] [set_screensave_active] set screensave active status to 1 failed, gle 329

2022-03-08 08:58:40 [12120/14436] [WARN] [set_screensave_active] set screensave active status to 1 failed, gle 329

2022-03-08 08:58:41 [12120/14436] [WARN] [set_screensave_active] set screensave active status to 1 failed, gle 329

2022-03-08 08:58:42 [12120/14436] [WARN] [set_screensave_active] set screensave active status to 1 failed, gle 329

In 8:58:33, I began to logon the Win10.And, In 8:58:35, I logined the Win10.The API SystemParametersInfo is called every second for ten seconds. After 8:58:36, the system was not in lock states. But SystemParametersInfo also return error code 329.

  • 1
    The value returned by `GetLastError` is meaningless here. As the [documentation](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-systemparametersinfoa) explains, `GetLastError` will only return a meaningful value in case `SystemParametersInfo` returns zero. The code never evaluates whether this condition is true. – IInspectable Mar 22 '22 at 07:06
  • 1
    Your code run during Windows login process, it is in system Lock state. – Junjie Zhu - MSFT Mar 22 '22 at 09:17
  • Hey, bros.Thank you for your reply. You may not understand my question. So I provide my log file. – guohan zhao Mar 29 '22 at 02:59
  • Yes, we understand your question. And both the previous comments you received are correct. You can't do what you're trying to do. And it makes no sense to activate the screensaver during the login process. Why are you needing to do this? What are you actually trying to achieve? – Ken White Mar 29 '22 at 03:06
  • Your code is wrong. The value of GetLastError is meaningless, because you do not check to see if it's safe to call first. Read the documentation, and correct your code to only call GetLastError if SystemParametersInfo actually returns a failure value. You're the one who does not understand, not us. – Ken White Mar 29 '22 at 03:28
  • I'm sorry for the misunderstanding and thank's for your patience! First, Incorrect use of GetLastError is that I didn't show the whole thing for convenience. Second, My goal is not to activate the screensaver during login process. The code about SystemParametersInfo runs in one of my System processes. I wonder why SystemParametersInfo returns errors even though I am already on the desktop. – guohan zhao Mar 29 '22 at 06:38
  • I tested it on the computer and found nothing wrong. You need check the Power Settings on your computer – Junjie Zhu - MSFT Apr 04 '22 at 04:09

0 Answers0