Registry settings immediate effect using C#

梦想与她 提交于 2019-11-29 15:49:36

Try this...

private const int HWND_BROADCAST = 0xffff;
private const int WM_WININICHANGE = 0x001a, WM_SETTINGCHANGE = WM_WININICHANGE, INI_INTL = 1;

SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, INI_INTL);

[DllImport("user32.dll")]
private static extern int SendMessage(int hWnd, uint wMsg, uint wParam, uint lParam);

This will notify all applications that changes have been made to the registry, and those programs that accept the notification shuould reload their settings.

Note that not all applications may do this, but things like control panel should.

I haven't tested this, but I suspect you only have to close all your explorer.exe processes for this to take effect.

Note that the desktop and taskbar are provided by explorer.exe, so you'll need to start a new one after closing them all.

It's a bit hostile, because the user might have Explorer windows that they don't want to lose, so do it only if it's not going to annoy people. 8-)

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