public static void monitor_usb_devices() { var md = new monitor_devices() { added_device = add_dump_info, deleted_device = del_dump_info }; //md.monitor("Win32_USBHub"); md.monitor("Win32_USBControllerDevice"); }
/* example: * monitor_usb_devices("Win32_USBControllerDevice"); * monitor_usb_devices("Win32_USBHub"); */ public static void monitor_usb_devices(string usb_class) { var md = new monitor_devices() { added_device = on_added_device_dump_info, deleted_device = on_deleted_device_dump_info }; md.monitor(usb_class); Thread.Sleep(2000000); }
private drive_root() { var existing_devices = find_devices.find_objects("Win32_USBHub"); foreach (var device in existing_devices) { if (device.ContainsKey("PNPDeviceID")) { var device_id = device["PNPDeviceID"]; string vid_pid = "", unique_id = ""; if (usb_util.pnp_device_id_to_vidpid_and_unique_id(device_id, ref vid_pid, ref unique_id)) { lock (this) vidpid_to_unique_id_.Add(vid_pid, unique_id); } } } var existing_controller_devices = find_devices.find_objects("Win32_USBControllerDevice"); foreach (var device in existing_controller_devices) { if (device.ContainsKey("Dependent")) { var device_id = device["Dependent"]; string vid_pid = "", unique_id = ""; if (usb_util.dependent_to_vidpid_and_unique_id(device_id, ref vid_pid, ref unique_id)) { lock (this) if (!vidpid_to_unique_id_.ContainsKey(vid_pid)) { vidpid_to_unique_id_.Add(vid_pid, unique_id); } } } } refresh(); monitor_usbhub_devices_.added_device += device_added; monitor_usbhub_devices_.deleted_device += device_removed; monitor_usbhub_devices_.monitor("Win32_USBHub"); monitor_controller_devices_.added_device += device_added_controller; monitor_controller_devices_.deleted_device += device_removed_controller; monitor_controller_devices_.monitor("Win32_USBControllerDevice"); new Thread(win32_util.check_for_dialogs_thread) { IsBackground = true }.Start(); }
private drive_root() { // not really proud of swallowing exceptions here, but otherwise if we were not able to create the drive_root object, // any other function would likely end up throwing try { var existing_devices = find_devices.find_objects("Win32_USBHub"); foreach (var device in existing_devices) { if (device.ContainsKey("PNPDeviceID")) { var device_id = device["PNPDeviceID"]; string vid_pid = "", unique_id = ""; if (usb_util.pnp_device_id_to_vidpid_and_unique_id(device_id, ref vid_pid, ref unique_id)) { add_vidpid(vid_pid, unique_id); } } } } catch { } try { var existing_controller_devices = find_devices.find_objects("Win32_USBControllerDevice"); foreach (var device in existing_controller_devices) { if (device.ContainsKey("Dependent")) { var device_id = device["Dependent"]; string vid_pid = "", unique_id = ""; if (usb_util.dependent_to_vidpid_and_unique_id(device_id, ref vid_pid, ref unique_id)) { add_vidpid(vid_pid, unique_id); } } } } catch { } try { refresh(); } catch { } try { monitor_usbhub_devices_.added_device += device_added; monitor_usbhub_devices_.deleted_device += device_removed; monitor_usbhub_devices_.monitor("Win32_USBHub"); } catch { } try { monitor_controller_devices_.added_device += device_added_controller; monitor_controller_devices_.deleted_device += device_removed_controller; monitor_controller_devices_.monitor("Win32_USBControllerDevice"); } catch { } new Thread(win32_util.check_for_dialogs_thread) { IsBackground = true }.Start(); }