How do I disable a system device? [duplicate]

假装没事ソ 提交于 2019-11-27 14:41:39
Mel Green

This article at CodeProject has some really nifty C# code for accomplishing this:

http://www.codeproject.com/KB/cs/HardwareHelper.aspx

In the end you simply make a call such as:

HH_Lib hwh = new HH_Lib();  hwh.SetDeviceState("MyDevice", /*Enable*/ true); hwh.SetDeviceState("MyDevice", /*Disable*/ false); 

To futher Mel Green's answer, the hardware helper library uses interop to call the Windows API (setupapi), specifically the SetupDiSetClassInstallParams method. Of course there are other calls here which are used to look up the device details etc.

One thing to consider that if you are running as a standard user or unprivileged account you will not be able to use this to control (enable/disable etc) hardware devices.

For more details have a look at http://www.pinvoke.net (and for the specific call: http://pinvoke.net/default.aspx/setupapi.SetupDiSetClassInstallParam )

I know this is an old question but I came across it with the same problem. To solve it, I had to use the new DevCon available at the TechNet wiki. The CodeProject article was helpful but in the end it was easier to just rely on the updated DevCon. Unfortunately it appears to only be available in the Windows Driver Kit which is over 600mb.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!