This library provides functionalities to list USB devices on Windows and handle events for device changes. It is based on C++ code and utilizes Windows IOCTL, setupapi.dll
, kernel32.dll
, and fmifs.dll
.
- List all connected USB devices
- Monitor USB device connection and disconnection events
- Filter USB devices by VID, PID, and Service
- .Net Core 8.0
- Windows Desktop
- Disk Drive
- Disk Partition
- Logical Disk
- Connected
- Disconnected
To install this library, clone the repository and build the solution using Visual Studio.
git clone https://github.com/bakhshipoor/USBDevices.git
cd USBDevices
- Create a new instance of the
USBDevicesList
class:
public USBDevicesList USBDevicesCollection { get; set; }
USBDevicesCollection = new USBDevicesList();
- Enable or disable connection and disconnection events as needed:
USBDevicesCollection.ConnectedEventStatus = false;
USBDevicesCollection.DisconnectedEventStatus = true;
- Enable device filtering and set filters:
USBDevicesCollection.EnableFilterDevice();
USBDevicesCollection.FilterDeviceStatus = true;
USBDevicesCollection.SetDeviceToFilter("xxxx", "yyyy", "Service Name");
- Add event handlers for initial collection completion and device changes:
USBDevicesCollection.InitialCollectionsComplete += USBDevicesCollections_InitialCollectionsComplete;
USBDevicesCollection.DeviceChanged += USBDevicesCollections_DeviceChanged;
- Start monitoring USB devices:
USBDevicesCollection.Start();
- Access the list of USB devices:
ObservableCollection<USBDevice> devices = USBDevicesCollection.USBDevices;
This library includes two example projects:
USBDevicesDemo
: A simple WPF application to view properties of connected USB devices.CopyFilesToFlash
: A WPF MVVM application that automatically copies files to a USB flash drive.
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please fork the repository and submit a pull request.
Thanks to all contributors and supporters.
Feel free to check the repository at USBDevices.