简体   繁体   English

在Windows中使用C#启用/禁用硬件设备

[英]Enabling / Disabling a Hardware Device in Windows using C#

I am working on a project that requires me to check for a disabled device in Windows and if that device is found disabled, the program should enable it. 我正在一个项目上,该项目需要我在Windows中检查禁用的设备,如果发现该设备已禁用,则程序应启用它。

I have been using the following solution from a previous answer.. 我一直在从先前的答案中使用以下解决方案。

How do I disable a system device programatically? 如何以编程方式禁用系统设备?

Though I am receiving the following error when running it... 虽然我在运行它时收到以下错误...

在此处输入图片说明

I am calling the program as shown in the linked post and am running it as soon as my program starts as shown, 我正在按链接文章中所示的程序进行调用,并在程序如图所示启动后立即运行,

private void Form1_Load(object sender, EventArgs e)
    {

        DisableHardware.DisableDevice(n => n.ToUpperInvariant().Contains("VID_11CA&PID_0219"), false);

    }

On the system I am using for testing, I already have the device disabled (I am looking to enable it). 在我用于测试的系统上,我已经禁用了设备(我希望启用它)。 I have tried building on different build configurations (x86, AnyCPU) and have tested on Windows XP and on Windows 7 but with the same issue. 我尝试在不同的构建配置(x86,AnyCPU)上进行构建,并在Windows XP和Windows 7上进行了测试,但存在相同的问题。

Any suggestions? 有什么建议么?

经过许多头痛和反复试验之后,最好的解决方案是简单地使用devcon来处理我的设备管理并通过带有适当参数的程序来处理devcon的执行。

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

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