USBDevices
This Library List of USB devices in Windows and events for changes
Install / Use
/learn @bakhshipoor/USBDevicesREADME
USB Devices Library
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.
Features
- List all connected USB devices
- Monitor USB device connection and disconnection events
- Filter USB devices by VID, PID, and Service
Requirements
- .Net Core 8.0
- Windows Desktop
Supported Interfaces
- Disk Drive
- Disk Partition
- Logical Disk
Event Types
- Connected
- Disconnected
Installation
To install this library, clone the repository and build the solution using Visual Studio.
git clone https://github.com/bakhshipoor/USBDevices.git
cd USBDevices
Usage
- Create a new instance of the
USBDevicesListclass:
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;
Examples
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.
Screenshots

License
This project is licensed under the MIT License. See the LICENSE file for details.
Contributing
Contributions are welcome! Please fork the repository and submit a pull request.
Acknowledgements
Thanks to all contributors and supporters.
Feel free to check the repository at USBDevices.
