隐藏磁盘驱动器

实现效果:

  

知识运用:
  

实现代码:

        private void button1_Click(object sender, EventArgs e)
        {
            byte[] bytes;
            string flags="";
            if (radioButton1.Checked == true)
            {
                bytes = new byte[] { 04, 00, 00, 00 };
                flags = "C盘";
            }
            else if(radioButton2.Checked==true)
            {
                bytes = new byte[] { 08,00,00,00 };
                flags = "D盘";
            }
            else if (radioButton3.Checked == true)
            {
                bytes = new byte[] { 16, 00, 00, 00 };
                flags = "E盘";
            }
            else
            { return; }
            HideDisk(bytes);
            if (MessageBox.Show("隐藏磁盘:" + flags + "成功") == DialogResult.OK)
                RefreshSystem();
        }
        private void HideDisk(byte[] bts)
        {
            try
            {
                RegistryKey rk = Registry.CurrentUser.CreateSubKey(@"SoftwareMicrosoftWindowsCurrentVersionPoliciesExplorer");
                rk.SetValue("NoDrives",bts,RegistryValueKind.Binary);
            }
            catch (Exception E)
            { MessageBox.Show(E.Message); }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            HideDisk(new byte[] { 16, 16, 16, 16, 16, 16, 16, 16});
            RefreshSystem();
        }

  

原文地址:https://www.cnblogs.com/feiyucha/p/10333592.html