Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i'm trying to catch an event that occurs when i insert my phone to the usb.
i use this code:
C#
var scope = new ManagementScope("root\\cimv2") { Options = { EnablePrivileges = true } };
var q = new WqlEventQuery
       {
           EventClassName = "__InstanceCreationEvent",
           WithinInterval = new TimeSpan(0, 0, 3),
           Condition = @"TargetInstance ISA 'Win32_USBControllerdevice'"
       };
var w = new ManagementEventWatcher(scope, q);
w.EventArrived += UsbConnect;
w.Start();

it works fine for any disk on key, but when i connect a smart phone the event arived when the phone is connected and not when i give the phone permisiion to act like usb devie.

this means that in phones there is another event that is not the connection event but another one.
i know that the Operating System have this event because just when you press on "use Usb Device" it's open the autorun window.

thanks a lot
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900