Skip to content

bakhshipoor/USBDevices

Repository files navigation

USB Devices Library

This Library List And Event USB Devices and Filter them

  • This library based on C++ codes. Using Windows IOCTL and C++ header files.

  • Using setupapi.dll, kernel32.dll and fmifs.dll files.

  • .Net Core 8.0

  • Windows Desktop

  • List of USB Devices in pc

  • Supported interfaces:

    • Disk Drive
    • Disk Partition
    • Logical Disk
  • Event Types:

    • Connected
    • Disconnected

Usage

  1. Create new instance of class USBDevicesList

    public USBDevicesList USBDevicesCollection { get; set; }
    USBDevicesCollection = new();
  2. By default Connected and Disconnected events are enabled if you want you can disable each of them by:

    USBDevicesCollection.ConnectedEventStatus = false;;
    USBDevicesCollection.DisconnectedEventStatus = true;
  3. You can set filter to monitor usb devices. In this case you should enable the filter status by:

    USBDevicesCollection.EnableFilterDevice();

    you can diable filter status by:

    USBDevicesCollection.FilterDeviceStatus = true;

    after enabling, set VID, PID or Service to filter. You can fillter by any of VID, PID, Service. Such as SetDeviceToFilter("xxxx", "yyyy", "Service Name"). The VID value cant be null any other nullable. Service Name such as a USBSTOR.

    USBDevicesCollection.SetDeviceToFilter("xxxx", "yyyy", "Service Name");
  4. Add Events :

    USBDevicesCollection.InitialCollectionsComplete += USBDevicesCollections_InitialCollectionsComplete;
    USBDevicesCollection.DeviceChanged += USBDevicesCollections_DeviceChanged;
  5. After initial USBDevices class you should start the monitiring by Start():

    USBDevicesCollection.Start();
  6. USBDevicesList have property ObservableCollection<USBDevice> USBDevices you can access list of usb device can enumrate this observable collection.

This Library have two examples of usage of this library.

  1. USBDevicesDemo a very simple WPF example to view properties of devices.
  2. CopyFilesToFlash a simple WPF MVVM example to work with storage interface. This example copy batch of files to usb flash disk automatically. This examples not prepared to publish just for undrestanding how to work.

USBDevicesDemo-1

USBDevicesDemo-2

USBDevicesDemo-3

USBDevicesDemo-4

CopyFilesToFlash-1

CopyFilesToFlash-2