Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using WMI querries to detect CD/Network/removeable-drives

18 views
Skip to first unread message

Gregers

unread,
Feb 10, 2008, 1:11:01 PM2/10/08
to
Hi

I want to detect whenever a CD is inserted/ejected, a network drive is
connected/disconnected and whenever a removeable storage device (USB stick,
SD card, USB harddisk, etc.) is attached/removed.

To do this i have been using WMI events:

WqlEventQuery q = new WqlEventQuery();
q.EventClassName = "__InstanceOperationEvent";
q.WithinInterval = new TimeSpan(0, 0, 5);
q.Condition = @"TargetInstance ISA 'Win32_DiskDrive' or
(TargetInstance ISA 'Win32_LogicalDisk' and TargetInstance.DriveType = 5)";

ManagementEventWatcher w = new ManagementEventWatcher(q);
w.EventArrived += new EventArrivedEventHandler(this.SomethingEventHandler);
w.Start();

Using TargetInstance ISA 'Win32_DiskDrive' in the query takes care of
detecting both removeable devices and network drives, however it has the
sideeffect that it makes any floppy drives become active any time you querry
(in this instance every 5seconds). This has been an issue with some of our
customers, since they find the constant "rrrrrr..... rrrrrr....
RRrRRrrrRR...."-noice quiete nerving .

We have removed a similar problem from the CD/DVD drives (where it would be
constantly spinning) by using the second part of the querry, instead of
querrying directly for TargetInstance ISA 'Win32_CDROMDrive'.

Any input on how to write a query which only detects the specific drive
types which i am interested in is very welcome!

Thanks in advance
Gregers

mauriziocolucci

unread,
Sep 22, 2009, 8:33:30 AM9/22/09
to
I have the same problem with floppy drives. I was wondering if you have solved it...

Posted as a reply to:

Using WMI querries to detect CD/Network/removeable-drives
10-Feb-08

Hi

Thanks in advance
Gregers

EggHeadCafe - Software Developer Portal of Choice
WPF And The Model View View Model Pattern
http://www.eggheadcafe.com/tutorials/aspnet/ec832ac7-6e4c-4ea8-81ab-7374d3da3425/wpf-and-the-model-view-vi.aspx

0 new messages