A comprehensive .NET library for identifying and categorizing disk drives and storage devices. This utility provides detailed information about physical, virtual, network, and removable storage devices in Windows systems.
- code was generated by us.anthropic.claude-3-7-sonnet-20250219-v1:0
- Detection of local, removable, network, and virtual drives
- Determination of mount types (physical, virtual, network)
- Detection of removable media with or without media present
- Comprehensive hardware information including:
- Interface types and bus connections
- Serial numbers and model information
- Drive health status
- Partition style (MBR/GPT)
- Output formatting for both console tables and CSV
- Support for filtering by device type and ready status
PM> Install-Package DiskDeviceUtility
dotnet add package DiskDeviceUtility
// Create an instance of the disk info utility
DiskDeviceInfo diskInfo = new DiskDeviceInfo();
// Get all disk devices
List<DiskDevice> allDevices = diskInfo.GetDiskDevices();
// Get only ready/mounted local drives
List<DiskDevice> localDrives = diskInfo.GetDiskDevices(DeviceType.Local, true);
// Print disk information to console
diskInfo.PrintDiskDevices(allDevices);
// Export to CSV
diskInfo.PrintDiskDevices(allDevices, OutputFormat.CSV);
// Get all disk devices including empty card readers or optical drives
List<DiskDevice> allDevices = diskInfo.GetDiskDevices(onlyReady: false);
// Check which removable devices have media
foreach (DiskDevice device in allDevices.Where(d => d.DeviceType == DeviceType.Removable)) {
Console.WriteLine($"{device.Model}: {(device.IsReady ? "Has Media" : "No Media")}");
}
// Get only network drives
List<DiskDevice> networkDrives = diskInfo.GetDiskDevices(DeviceType.Network);
foreach (DiskDevice drive in networkDrives) {
Console.WriteLine($"{drive.DriveLetter} -> {drive.DeviceID}");
}
List<DiskDevice> allDevices = diskInfo.GetDiskDevices();
var physicalDrives = allDevices.Where(d => d.MountType == MountType.Physical);
var virtualDrives = allDevices.Where(d => d.MountType == MountType.Virtual);
Console.WriteLine($"Physical drives: {physicalDrives.Count()}");
Console.WriteLine($"Virtual drives: {virtualDrives.Count()}");
The main class for retrieving disk device information.
-
GetDiskDevices(DeviceType? deviceTypeFilter = null, Boolean onlyReady = false)
Returns a list of disk devices matching the specified filters. -
PrintDiskDevices(List devices, OutputFormat format = OutputFormat.Table)
Prints disk information to the console in the specified format.
Represents a single disk device with its properties.
- DriveLetter: Drive letter with colon (e.g., "C:")
- VolumeName: Volume label or name of the drive
- DeviceType: Type of storage device (Local, Removable, etc.)
- MountType: How the device is mounted (Physical, Network, Virtual)
- IsReady: Whether the drive has media and is ready for I/O operations
- FileSystem: File system format (NTFS, FAT32, exFAT, etc.)
- TotalSize: Total size of the drive in bytes
- FreeSpace: Available free space in bytes
- DeviceID: Windows device ID
- Model: Manufacturer and model information
- SerialNumber: Serial number of the device
- InterfaceType: Interface type (IDE, SATA, SCSI, USB, etc.)
- MediaType: Media type (Fixed hard disk, Removable media, etc.)
- FirmwareRevision: Firmware revision of the device
- Manufacturer: Device manufacturer name
- PartitionStyle: Partition style (MBR, GPT, etc.)
- BytesPerSector: Sector size in bytes
- HealthStatus: Health status of the device if available
- VolumeGuid: GUID of the volume
- BusType: Bus type (USB, SATA, NVMe, etc.)
- LastAccessed: Timestamp of when the drive was last accessed
- Unknown: Unknown device type
- Local: Fixed local disk (internal HDD, SSD)
- Removable: Removable media (USB drives, memory cards)
- Network: Network mapped drive
- CDRom: Optical drive (CD, DVD, Blu-ray)
- Ram: RAM disk
- Unknown: Mount type could not be determined
- Physical: Physical device (directly connected via hardware interface)
- Network: Network mounted device
- Virtual: Virtual device (software-based)
- Table: Formatted table output
- CSV: CSV format for data import
- .NET Framework 4.5+ or .NET Core 3.1+/NET 5.0+
- System.Management.dll (for enhanced Windows features)
MIT License
Copyright (c) 2025 Lynne Whitehorn / Silver Star Brands (https://github.com/lynnewu)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.