如何禁用系统设备? [重复]

时间:2022-08-25 23:36:33

This question already has an answer here:

这个问题在这里已有答案:

Is there any way to disable a system device from C#.NET.

有没有办法从C#.NET禁用系统设备。

Basically emulating when you go to Device Manager and disable a device that way?

当您转到设备管理器并以此方式禁用设备时基本上模拟?

I am assuming there is a WinAPI function that I can invoke, but I don't know which one it is?

我假设有一个我可以调用的WinAPI函数,但我不知道它是哪一个?

The reason I need to do this is that I need to disable and straight after enable the device again.

我需要这样做的原因是我需要在再次启用设备后禁用并直接启用。

I need to work in Windows XP and Vista (x86 & x64). I had a look at something called "DevCon" but it doesn't seem to work on Vista x64.

我需要在Windows XP和Vista(x86和x64)中工作。我看了一下名为“DevCon”的东西,但它似乎不适用于Vista x64。

Thanks.

For the answer see here: How do I disable a system device programatically?

有关答案,请参阅此处:如何以编程方式禁用系统设备?

3 个解决方案

#1


12  

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

CodeProject上的这篇文章有一些非常好的C#代码来完成这个:

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

如何禁用系统设备? [重复]

#2


9  

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.

为了进一步了解Mel Green的答案,硬件帮助程序库使用interop来调用Windows API(setupapi),特别是SetupDiSetClassInstallParams方法。当然这里还有其他调用用于查找设备细节等。

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 )

有关详细信息,请查看http://www.pinvoke.net(以及具体的电话:http://pinvoke.net/default.aspx/setupapi.SetupDiSetClassInstallParam)

#3


4  

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.

我知道这是一个老问题,但我遇到了同样的问题。为了解决这个问题,我不得不使用TechNet wiki上提供的新DevCon。 CodeProject文章很有帮助,但最终只需依赖更新的DevCon就更容易了。不幸的是,它似乎只能在超过600mb的Windows驱动程序工具包中使用。

#1


12  

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

CodeProject上的这篇文章有一些非常好的C#代码来完成这个:

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

如何禁用系统设备? [重复]

#2


9  

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.

为了进一步了解Mel Green的答案,硬件帮助程序库使用interop来调用Windows API(setupapi),特别是SetupDiSetClassInstallParams方法。当然这里还有其他调用用于查找设备细节等。

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 )

有关详细信息,请查看http://www.pinvoke.net(以及具体的电话:http://pinvoke.net/default.aspx/setupapi.SetupDiSetClassInstallParam)

#3


4  

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.

我知道这是一个老问题,但我遇到了同样的问题。为了解决这个问题,我不得不使用TechNet wiki上提供的新DevCon。 CodeProject文章很有帮助,但最终只需依赖更新的DevCon就更容易了。不幸的是,它似乎只能在超过600mb的Windows驱动程序工具包中使用。