How to refresh logon screensaver parameter changes?

让人想犯罪 __ 提交于 2019-12-24 05:32:22

问题


I have a Windows service that may change the timeout on the logon screensaver in Windows (as described here.) To do that I change the following registry key to the timeout in seconds:

HKEY_USERS\.DEFAULT\Control Panel\Desktop\ScreenSaveTimeOut

The issue is that how do I make OS "read" or refresh the actual screensaver timeout after a change in the registry key above?

My practice shows that it is refreshed (for sure) only when I reboot the system, but in my case I need it to be applied without the reboot.

EDIT_1: After suggestion below I tried, as it seems to me, all possible combinations of the flags for the following:

DWORD bsmInfo1 = BSM_ALLDESKTOPS;
DWORD dwFlgs = BSF_FORCEIFHUNG | BSF_IGNORECURRENTTASK | BSF_NOTIMEOUTIFNOTHUNG | BSF_SENDNOTIFYMESSAGE;
int nbsm1 = ::BroadcastSystemMessage(dwFlgs, &bsmInfo1, WM_SETTINGCHANGE, 0, (LPARAM)L"Windows");
DWORD bsmInfo2 = BSM_ALLDESKTOPS;
int nbsm2 = ::BroadcastSystemMessage(dwFlgs, &bsmInfo2, WM_SETTINGCHANGE, 0, (LPARAM)L"WindowsThemeElement");

to no avail :( I receive 1 as a result from both calls but it has no effect.


回答1:


I was able to resolve this.-.-.




回答2:


If your service is running in the same session as the logon screensaver then you can call SystemParametersInfo with the SPI_SETSCREENSAVETIMEOUT flag.

SystemParametersInfo broadcasts the WM_SETTINGCHANGE message to all top level windows to indicate that a parameter has changed. If your code isn't running in the correct session then you could use BroadcastSystemMessage with the BSM_ALLDESKTOPS flag to deliver the WM_SETTINGCHANGE message. However, this does require the SE_TCB_NAME privilege, so your code would have to be running as SYSTEM.

I haven't actually tried this cross-session, so I can't guarantee that it works.



来源:https://stackoverflow.com/questions/21085199/how-to-refresh-logon-screensaver-parameter-changes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!