注册表设置使用C#立竿见影的效果 [英] Registry settings immediate effect using C#

查看:176
本文介绍了注册表设置使用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.

推荐答案

试试这个...

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

这将通知已经作了修改注册表的所有应用程序,以及那些接受通知的程序shuould重新加载它们的设置。

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.

这篇关于注册表设置使用C#立竿见影的效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆