×

# C# 修改注册表禁用U盘

hqy hqy 发表于2026-04-08 16:57:42 浏览9 评论0

抢沙发发表评论

# C# 修改注册表禁用U盘

代码

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


打赏

本文链接:https://www.kinber.cn/post/6414.html 转载需授权!

分享到:


推荐本站淘宝优惠价购买喜欢的宝贝:

image.png

 您阅读本篇文章共花了: 

群贤毕至

访客