屏蔽和开启”关机“功能

Posted on 2019-01-28 23:52  努力成长静待花开  阅读(375)  评论(0编辑  收藏  举报

实现效果:

  

  

知识运用:

  注册表项中的NoClose键进行设置

实现代码:

        private void button1_Click(object sender, EventArgs e)
        {
            RegistryKey rk = Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\Explorer");
            rk.SetValue("NoClose",1);
            MessageBox.Show("屏蔽关机功能成功");
        }
        private void button2_Click(object sender, EventArgs e)
        {
            RegistryKey rk = Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\Explorer");
            rk.SetValue("NoClose", 0);
            MessageBox.Show("开启关机功能成功,重新启动生效");
        }