Can you show sample code for reading a drive label or volume name in .NET? I get the sense this requires WMI, but I am loathe to "drop-down" into WMI because it is like dropping down into a string-based SQL query in the sense that certain objects may not exist on certain versions of OSes or the user may not have the right to query certain data. I will be happy to be convinced that I'm wrong about WMI ...
No WMI required. The following will get all volume labels:
var labels = from drive in DriveInfo.GetDrives()
select drive.VolumeLabel
Call DriveInfo.GetDrives to get an array of drive information. Then look at DriveInfo.VolumeLabel
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With