禁止运行注册表

Posted on 2019-01-27 16:32  努力成长静待花开  阅读(249)  评论(0编辑  收藏  举报

实现效果:

  

知识运用:

  DisableRegistryTools键    //设置是否允许运行注册表程序

  1 表禁止 0 为允许

实现代码:

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                RegistryKey rk = Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System");
                rk.SetValue("DisableRegistryTools",1,RegistryValueKind.DWord);
                MessageBox.Show("注册表禁用成功!");
            }
            catch (Exception ex)
            { MessageBox.Show(ex.Message); }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                RegistryKey rk = Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System");
                rk.SetValue("DisableRegistryTools", 0, RegistryValueKind.DWord);
                MessageBox.Show("注册表启用用成功!");
            }
            catch (Exception ex)
            { MessageBox.Show(ex.Message); }
        }