DeviceInterfaceGUIDs using ManagementEventWatcher

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<p style="padding-right:0px; font-size:14px; vertical-align:baseline; clear:both; word-wrap:break-word; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; line-height:18px; text-align:left
Hello,
<p style="padding-right:0px; font-size:14px; vertical-align:baseline; clear:both; word-wrap:break-word; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; line-height:18px; text-align:left
Im writing USB listener using ManagementEventWatcher
<p style="padding-right:0px; font-size:14px; vertical-align:baseline; clear:both; word-wrap:break-word; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; line-height:18px; text-align:left
I need to get DeviceInterfaceGUIDs of arriving/removed USB device
<p style="padding-right:0px; font-size:14px; vertical-align:baseline; clear:both; word-wrap:break-word; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; line-height:18px; text-align:left
Is it possible?
<p style="padding-right:0px; font-size:14px; vertical-align:baseline; clear:both; word-wrap:break-word; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; line-height:18px; text-align:left
Here is my code
<p style="padding-right:0px; font-size:14px; vertical-align:baseline; clear:both; word-wrap:break-word; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; line-height:18px; text-align:left
from http://social.msdn.microsoft.com/forums/en-US/wpf/thread/983dc1ee-6208-4036-903f-3fd5674a1efb/ MSDN
<pre class="prettyprint public Listener()
{
WqlEventQuery _q = new WqlEventQuery("__InstanceOperationEvent", "TargetInstance ISA Win32_USBControllerDevice ");

_q.WithinInterval = TimeSpan.FromSeconds(1);

ManagementEventWatcher _w = new ManagementEventWatcher(_q);

_w.EventArrived += new EventArrivedEventHandler(onEventArrived);

_w.Start();

}
void onEventArrived(object sender, EventArrivedEventArgs e)
{
ManagementBaseObject baseObject = (ManagementBaseObject)e.NewEvent;

if (baseObject.ClassPath.ClassName.Equals("__InstanceCreationEvent"))
Console.WriteLine("A drive was connected");
else if (baseObject.ClassPath.ClassName.Equals("__InstanceDeletionEvent"))
Console.WriteLine("A drive was removed");
}

//Find Device Guid

}
}[/code]
<br/>
Thanks in advance
<br/>

View the full article
 
Back
Top