Registry settings immediate effect using C#
Asked Answered
C

2

3

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.

Concrete answered 27/6, 2009 at 6:11 Comment(2)
This is probably best asked on serverfault.comRufena
I presume you're aware you can do this through Group Policy, so I'll also presume you have some reason for not doing it that way.Guidon
A
6

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.

Aussie answered 27/6, 2009 at 11:53 Comment(0)
C
0

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-)

Commutual answered 27/6, 2009 at 6:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.