Does the WMI event Win32_VolumeChangeEvent work on Windows XP

Posted by Christian Rodemeyer on Stack Overflow See other posts from Stack Overflow or by Christian Rodemeyer
Published on 2009-05-19T12:03:16Z Indexed on 2010/03/25 12:03 UTC
Read the original article Hit count: 645

Filed under:
|

I'm trying to use the following c# code to detect the attached/removed event of usb mass storage devices. I'm using the Win32_VolumeChangeEvent.

  
// Initialize an event watcher and subscribe to events that match this query            
var _watcher = new ManagementEventWatcher("select * from Win32_VolumeChangeEvent");
_watcher.EventArrived += OnDeviceChanged;
_watcher.Start();

void OnDeviceChanged(object sender, EventArrivedEventArgs args)
{
    Console.WriteLine(args.NewEvent.GetText(TextFormat.Mof));
}

The problem is that this works fine on Vista but it doesn't work on XP at all (no events received). The Microsoft documentation says that this should work (http://msdn.microsoft.com/en-us/library/aa394516(VS.85).aspx). I googled for this quite a while and found other that have this problem too. But I also found a couple of articles which claim that this kind of query (mostly in vbscript) works with XP. But I cannot find some offical information from microsoft for this issue and I can't believe that Microsoft have overlooked this issue for three service packs.

So my question is: has anybody used the Win32_VolumeChangeEvent with success on XP or can provide a link/explanation why it shouldn't work on XP?

© Stack Overflow or respective owner

Related posts about wmi

Related posts about usb