How do I get information about recently connected USB device?

后端 未结 3 1593
后悔当初
后悔当初 2020-12-07 04:08

I can catch when usb device is connected with Win32_DeviceChangeEvent

but there are only 3 properties allowed to view

class Win32_DeviceChangeEvent          


        
3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-07 04:47

    You can use ORMi to create a watcher so you can get information about any new device:

    WMIHelper helper = new WMIHelper("root\\CimV2");
    
    WMIWatcher watcher = new WMIWatcher("root\\CimV2", "SELECT * FROM __InstanceCreationEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_PnPEntity'");
    watcher.WMIEventArrived += Watcher_WMIEventArrived;
    

    And then you can watch for the events:

    private static void Watcher_WMIEventArrived(object sender, WMIEventArgs e)
    {
        //DO YOUR WORK
    }
    

提交回复
热议问题