C#制作个USB禁用启用工具

using System;
using Microsoft.Win32;
using System.Text;
using System.Windows.Forms;
/****************************************
* USB应用
* David
* 2012/3/31
* *************************************
*/
namespace USB应用
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            RegistryKey regKey = Registry.LocalMachine; //读取注册列表HKEY_LOCAL_MACHINE
            string keyPath = @"SYSTEM\CurrentControlSet\Services\USBSTOR"//USB 大容量存储驱动程序
            RegistryKey openKey = regKey.OpenSubKey(keyPath, true);
            openKey.SetValue("Start"3); //设置键值对(3)为开启USB(4)为关闭
            openKey.Close(); //关闭注册列表读写流
            MessageBox.Show("USB以启用!");
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            RegistryKey regKey = Registry.LocalMachine;
            string keyPath = @"SYSTEM\CurrentControlSet\Services\USBSTOR";
            RegistryKey openKey = regKey.OpenSubKey(keyPath, true);
            openKey.SetValue("Start"4);
            openKey.Close();
            MessageBox.Show("USB以禁用!");
            this.Close();
        }
    }
posted @ 2012-03-31 14:34  强哥  阅读(1147)  评论(0)    收藏  举报