Basics: C# WinForms desktop application targeting Dot Net 4.
I am enumerating all drives on a system using System.IO.DriveInfo. This works quite well and can also tell me what type of drive it is (fixed/network/cd-rom, etc). It can also give me the VolumeLabel - this works as desired on local drives, but for mapped network drives it gives you the VolumeLabel of the logical disk as defined on the host computer. In Windows Explorer, you can give any mapped drive a friendly name. Is there a way to programmatically retrieve this friendly name? This name is obviously the one that is familiar to the person using the computer.
For example, in the image below both "Critical" and "NonCritical" might be different shares on the same logical disk with a volume name "Data" on the host computer. Querying WMI for VolumeName returns "Data", and the other queries return just the drive letter, or else nothing.
I have looked at the info available through WMI (see: How to programmatically discover mapped network drives on system and their server names?) but there doesn't seem to be a property that returns this friendly name. I've looked at Caption, Description, SystemName, and VolumeName - like this:
private void NetworkDrives()
{
try
{
var searcher = new ManagementObjectSearcher(
"root\\CIMV2",
"SELECT * FROM Win32_MappedLogicalDisk");
TreeNode share;
TreeNode property;
foreach (ManagementObject queryObj in searcher.Get())
{
share = new TreeNode("Name:" + queryObj["Name"]);
share.Nodes.Add("Caption: " + queryObj["Caption"]);
share.Nodes.Add("Description: " + queryObj["Description"]);
share.Nodes.Add("SystemName: " + queryObj["SystemName"]);
share.Nodes.Add("VolumeName: " + queryObj["VolumeName"]);
share.Nodes.Add("DeviceID: " + queryObj["DeviceID"]);
treeView1.Nodes.Add(share);
}
}
catch (ManagementException ex)
{
MessageBox.Show("An error occurred while querying for WMI data: " + ex.Message);
}
}
Thanks in advance.
Win32_DiskDrive
)? – Dishman