日期:2014-05-17 浏览次数:21118 次
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