How do I disable a system device? [duplicate]

Is there any way to disable a system device from 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?

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.

Thanks.

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


Solution 1:

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 )

Solution 2:

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.