title: How to identify what device was plugged into the USB slot?
body: <p>I want to detect when the user plugs in or removes a USB sound card.  I've managed to actually catch the event when this happens, but I can't tell what just got plugged in.</p>
  
  <p>I tried an approach based on <a href="https://stackoverflow.com/questions/5278860/using-wmi-to-identify-which-device-caused-a-win32-devicechangeevent">this</a> question: </p>
  
  <pre><code>string query =
      "SELECT * FROM __InstanceCreationEvent " +
      "WITHIN 2 "
    + "WHERE TargetInstance ISA 'Win32_PnPEntity'";
  var watcher = new ManagementEventWatcher(query);
  watcher.EventArrived += new EventArrivedEventHandler(watcher_EventArrived);
  watcher.Start();
  </code></pre>
  
  <p>While I get the notifications via the EventArrived event, I have no idea how to determine the actual name of the device that just got plugged in.  I've gone through every property and couldn't make heads or tails out of it.</p>
  
  <p>I also tried a different query: </p>
  
  <pre><code>var query = new WqlEventQuery("SELECT * FROM Win32_DeviceChangeEvent where EventType = 1 or EventType = 2");
  var watcher = new ManagementEventWatcher(query);
  watcher.EventArrived += watcher_EventArrived;
  watcher.Stopped += watcher_Stopped;
  watcher.Query = query;
  watcher.Start();
  </code></pre>
  
  <p>but also to no avail.  Is there a way to find the name of the device that got plugged in or removed.</p>
  
  <p>The bottom line is that I'd like to know when a USB sound card is plugged in or removed from the system.  It should work on Windows 7 and Vista (though I will settle for Win7 only).</p>
  
  <p>EDIT: Based on the suggestions by the winning submitter, I've created a <a href="http://pastebin.com/amLAHuEa" rel="nofollow noreferrer">full solution</a> that wraps all the functionality.</p>