title: Disable USB Device Programmatically
body: <p>I've got a HID device that I need to programmatically disable in VB.NET. I downloaded the WMICodeCreator, and used that to generate the code to ID my device, but the code creator doesn't give me access to any methods to disable the device (only query for it's status). </p>
  
  <p>How to disable the device? </p>
  
  <pre><code>Imports System
  Imports System.Management
  Imports System.Windows.Forms
  
  Namespace WMISample
  
      Public Class MyWMIQuery
  
          Public Overloads Shared Function Main() As Integer
  
              Try
                  Dim searcher As New ManagementObjectSearcher( _
                          "root\CIMV2", _
                          "SELECT * FROM Win32_USBDevice WHERE DeviceID =      'USB\\VID_0596&amp;PID_0586\\1B0033000251343439343037'") 
  
                  For Each queryObj As ManagementObject in searcher.Get()
  
                      Console.WriteLine("-----------------------------------")
                      Console.WriteLine("Win32_USBDevice instance")
                      Console.WriteLine("-----------------------------------")
                      Console.WriteLine("DeviceID: {0}", queryObj("DeviceID"))
                  Next
              Catch err As ManagementException
                  MessageBox.Show("An error occurred while querying for WMI data: " &amp; err.Message)
              End Try
          End Function
      End Class
  End Namespace
  </code></pre>