禁止使用命令提示符

Posted on 2019-01-29 21:09  努力成长静待花开  阅读(169)  评论(0编辑  收藏  举报

实现效果:

  

知识运用:
  
RegistryKey类的CreateSubKey和SetValue方法

实现代码:

        private void button1_Click(object sender, EventArgs e)
        {
            RegistryKey regMain;
            RegistryKey regChild;
            regMain = Registry.CurrentUser;
            regChild = regMain.CreateSubKey(@"Software\Policies\Microsoft\Windows\System");
            regChild.SetValue("DisableCMD",1);
            regChild.Close();
            MessageBox.Show("禁止成功!");
        }
        private void button2_Click(object sender, EventArgs e)
        {
            RegistryKey regMain;
            RegistryKey regChild;
            regMain = Registry.CurrentUser;
            regChild = regMain.CreateSubKey(@"Software\Policies\Microsoft\Windows\System");
            regChild.SetValue("DisableCMD", 0);
            regChild.Close();
            MessageBox.Show("禁止成功!");
        }