title: WMI and Win32_DeviceChangeEvent - Wrong event type returned?
body: <p>I am trying to register to a "Device added/ Device removed" event using WMI. When I say device - I mean something in the lines of a Disk-On-Key or any other device that has files on it which I can access...</p>
  
  <p>I am registering to the event, and the event is raised, but the EventType propery is different from the one I am expecting to see.</p>
  
  <p>The documentation (<a href="http://msdn.microsoft.com/en-us/library/aa394124(VS.85).aspx" rel="nofollow noreferrer">MSDN</a>) states : 1- config change, 2- Device added, 3-Device removed 4- Docking. For some reason I always get a value of 1. </p>
  
  <p>Any ideas ?</p>
  
  <p>Here's sample code : </p>
  
  <pre><code>public class WMIReceiveEvent
  {
      public WMIReceiveEvent()
      {
          try
          {
              WqlEventQuery query = new WqlEventQuery(
                  "SELECT * FROM Win32_DeviceChangeEvent");
  
              ManagementEventWatcher watcher = new ManagementEventWatcher(query);
              Console.WriteLine("Waiting for an event...");
  
              watcher.EventArrived += 
                  new EventArrivedEventHandler(
                  HandleEvent);
  
              // Start listening for events
              watcher.Start();
  
              // Do something while waiting for events
              System.Threading.Thread.Sleep(10000);
  
              // Stop listening for events
              watcher.Stop();
              return;
          }
          catch(ManagementException err)
          {
              MessageBox.Show("An error occurred while trying to receive an event: " + err.Message);
          }
      }
  
      private void HandleEvent(object sender,
          EventArrivedEventArgs e)
      {
          Console.WriteLine(e.NewEvent.GetPropertyValue["EventType"]);
      }
  
      public static void Main()
      {
          WMIReceiveEvent receiveEvent = new WMIReceiveEvent();
          return;
      }
  }
  </code></pre>