Skip to content

Gets a comprehensive list of disk devices on the system with their mounting information. Useful for determing which "drives" are actually local, physical devices. Easier to use than various Microsoft "solutions".

License

Notifications You must be signed in to change notification settings

lynnewu/DiskDeviceInfo

Repository files navigation

Disk Device Utility for .NET

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.

Notes

  • code was generated by us.anthropic.claude-3-7-sonnet-20250219-v1:0

Features

  • 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

Installation

Package Manager Console

PM> Install-Package DiskDeviceUtility

.NET CLI

dotnet add package DiskDeviceUtility

Quick Start

// 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);

Usage Examples

Detecting All Drives Including Empty Media Slots

// 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")}");
}

Finding Network Drives

// Get only network drives
List<DiskDevice> networkDrives = diskInfo.GetDiskDevices(DeviceType.Network);

foreach (DiskDevice drive in networkDrives) {
    Console.WriteLine($"{drive.DriveLetter} -> {drive.DeviceID}");
}

Examining Physical vs Virtual Drives

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()}");

API Reference

DiskDeviceInfo Class

The main class for retrieving disk device information.

Methods

  • 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.

DiskDevice Class

Represents a single disk device with its properties.

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

Enums

DeviceType

  • 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

MountType

  • Unknown: Mount type could not be determined
  • Physical: Physical device (directly connected via hardware interface)
  • Network: Network mounted device
  • Virtual: Virtual device (software-based)

OutputFormat

  • Table: Formatted table output
  • CSV: CSV format for data import

Requirements

  • .NET Framework 4.5+ or .NET Core 3.1+/NET 5.0+
  • System.Management.dll (for enhanced Windows features)

License

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.

About

Gets a comprehensive list of disk devices on the system with their mounting information. Useful for determing which "drives" are actually local, physical devices. Easier to use than various Microsoft "solutions".

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages