Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Registry settings immediate effect using C#

I have used the following code to disable the control panel:

RegistryKey RegKey = Registry.CurrentUser.CreateSubKey(
    @"Software\Microsoft\Windows\CurrentVersion\Policies\Explorer");
RegKey.SetValue("NoControlPanel", false, RegistryValueKind.DWord); 
RegKey.Close();

The above code disables control panel only after restarting, I would like to apply the setting immediately without restarting. Please help me.

like image 350
Suriyan Suresh Avatar asked May 22 '26 23:05

Suriyan Suresh


1 Answers

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.

like image 184
Martin Robins Avatar answered May 25 '26 13:05

Martin Robins



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!