15 January 2009

Enable/Disable a device programmatically with VB.Net using the setup api.

Very quickly...

Check in device manager to see if the device has "Disable" as an option when you R click it. If so then look at the properties, and find the "class guid" and "device instance id".

1) Get a handle to a device info set using SetupDiGetClassDevs - this will get all devices in a class.
2) Get device info data for each device in the class using SetupDiEnumDeviceInfo
3) Get the device instance id for each device using the device info data from (2) and SetupDiGetDeviceInstanceId.
4) Fill in a structure to say you want a property change and call SetupDiSetClassInstallParams. This sets the property in the device info set.
5) Call SetupDiCallClassInstaller to get the installer to make the changes stick.

2 comments:

  1. What about keyboards? How can I enable/disable a USB keyboard attached to my PC? I have more than one USB keyboard connected.

    Thank you :)

    Andy

    ReplyDelete
  2. do you have a vb.net walkthrough to close the usb port (so no current gets out of it) and to reopen the usb port (so electric current comes out) ?

    ReplyDelete