代码
C#
private void LockUsb(){ try { if (OperatingSystem.IsWindows()) { RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SYSTEM\\CurrentControlSet\\Services\\USBSTOR", true); if (key != null) { key.SetValue("Start", 4); } } } catch (Exception ex) { Console.WriteLine($"lock usb {ex}"); }}private void UnLockUsb(){ try { if (OperatingSystem.IsWindows()) { RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SYSTEM\\CurrentControlSet\\Services\\USBSTOR", true); if (key != null) { key.SetValue("Start", 3); } } } catch (Exception ex) { Console.WriteLine($"unlock usb {ex}"); }}
支付宝微信扫一扫,打赏作者吧~
