I'd like to get the Drive-Letter from the new plugged USB-Media(such as, HardDisks, USBSticks, CD-Cards ect.)
Please Note: I want only the new plugged. Not the existing ones.
For Example1: User plugs in a USB-Stick. The Method should return: "F:"
For Example2: User plugs in a External HDD with two Partition. The Method should return: "G:" and "H:"
I have the following code: But it just trigger the insert. Not the Drive-Letter.
public void TrigerUSBInsert()
{
try
{
WqlEventQuery w = new WqlEventQuery
{
EventClassName = "__InstanceCreationEvent",
Condition = "TargetInstance ISA 'Win32_USBControllerDevice'",
WithinInterval = new TimeSpan(0, 0, 2)
};
ManagementEventWatcher watch = new ManagementEventWatcher(w);
watch.EventArrived += new EventArrivedEventHandler(this.usbDetectionHandler);
watch.Start();
}
catch (Exception exception)
{
}
}
Thank you.