繁体   English   中英

我想使用C#控制台应用程序阻止USB端口

[英]I want to block USB Port using C# console application

我正在尝试制作一个可以通过代码修改Windows注册表的简单程序。我试图添加一个应用程序清单文件来为代码提供管理员权限,但似乎没有任何效果。

    try
        { 
            RegistryKey MyKey = Registry.LocalMachine.OpenSubKey("/SYSTEM/CurrentControlSet/Services/USBSTOR", true);
         //the control jumps to catch after the above line.
            MyKey.SetValue("Start", "4", RegistryValueKind.DWord);
            System.Console.WriteLine("Port locked");
            System.Console.ReadKey();
        }//throws a nullvaluerefrence exception
        catch
        {
            System.Console.WriteLine("There was an error");
            System.Console.ReadKey();
        }

MyKey.SetValue具有无效的参数。 string不能转换为int

MyKey.SetValue("Start", "4", RegistryValueKind.DWord);

将代码更改为:

MyKey.SetValue("Start", 0x4, RegistryValueKind.DWord);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM