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(); }