日期:2014-05-17  浏览次数:21100 次

ManagementEventWatcher如何判断连接的是手机
WINFORM监听USB插入拔出代码如下附加代码,插入拔出USB设备都能监听到,现在我想监听手机插入拔出
, getEventQuery.Condition = @"TargetInstance ISA 'Win32_DiskDrive' ";  这个值应该修改成什么呢


   public void ControlUSBConnectionStatu()
        {
            ManagementEventWatcher getEventWatcher = null;
            WqlEventQuery getEventQuery = null;
            ManagementOperationObserver getObserver = new ManagementOperationObserver();  //Bind to Loacl Machine and Watch the PortConnection   
            ManagementScope getScope = new ManagementScope("root\\CIMV2");
            getScope.Options.EnablePrivileges = true;//set requeired 
            try
            {
                getEventQuery = new WqlEventQuery();
                getEventQuery.EventClassName = "__InstanceOperationEvent";
                getEventQuery.WithinInterval = new TimeSpan(0, 0, 0, 1);
                getEventQuery.Condition = @"TargetInstance ISA 'Win32_DiskDrive' ";
                //[Disk must have DiskDrive fuck ]   
                //Event Watcher [Test Event and semd informatio to this message and create new informtion .]  
                getEventWatcher = new ManagementEventWatcher(getEventQuery);
                getEventWatcher.EventArrived += new EventArrivedEventHandler(getEventWatcher_EventArrived);
                getEventWatcher.Start();//Start Watch Event   
            }
            catch (Exception se)
            {
            }
            finally
            {
                // getEventWatcher.Stop();  
            }
        }

     &nb