c# Вставляем флэшку в компьютер и обрабатываем это событие


Thread t = new Thread(Flashwatcher);
t.Start();

//...
        private void Flashwatcher()
        {
            ManagementScope scope = new ManagementScope("root\\CIMV2");
            scope.Options.EnablePrivileges = true;
            
            
            WqlEventQuery query = new WqlEventQuery();
            query.EventClassName = "__InstanceCreationEvent";
            query.WithinInterval = new TimeSpan(0, 0, 1);
            query.Condition = @"TargetInstance ISA 'Win32_USBControllerdevice'";
            watcher = new ManagementEventWatcher(scope, query);
            watcher.Start();
            watcher.WaitForNextEvent();
        }

No comments:

Post a Comment