Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 227
Cheetah Avatar asked Oct 30 '08 23:10

Cheetah


People also ask

How do I get rid of duplicate drivers?

Click View tab and select Show hidden devices. Expand the branches in the device tree & look for the faded icons. These indicate unused device drivers. Right-click on it and select Uninstall.

Why are there duplicate drivers in Device Manager?

It means there are multiple devices using the same driver. If you had a dual monitor setup, you'd see two of the same monitor listed. You wouldn't want to remove one of them, would you? My Computer.


2 Answers

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 )

like image 182
Matthew Savage Avatar answered Oct 01 '22 03:10

Matthew Savage


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.

like image 23
Brian Hasden Avatar answered Oct 01 '22 04:10

Brian Hasden