views:

150

answers:

2

Possible Duplicates:
[.NET] How do I disable a system device?
Win32 API function to programatically enable/disable device

Is there a way, in C#, to programmatically disable and re-enable a device? I'm looking for essentially the same functionality that occurs when you go into device manager and right click on a device and disable or enable it. How can I do this in C#?

+1  A: 

Take a look at net-how-do-i-disable-a-system-device.

Will A
You meant to comment this as a double, right? ;)
Abel
That looks a lot like it's just using handles to windows to do this and it doesn't appear to work anywhere like Vista, 7 or 2008 R2. Interesting though.
Nissan Fan
@Abel - yeah, well at least I have done so now!
Will A
A: 

According to this link: http://bytes.com/topic/c-sharp/answers/513855-can-i-use-wmi-c-disable-enable-device

You need to interface with CfgMgr32 (Win32 API) to do this.

My first thought was to look at WMI but it's not there.

DevCon, which comes with the Device Drive Toolkit, provides a CLI to do this.

http://msdn.microsoft.com/en-us/library/ff541193(VS.85).aspx

Nissan Fan