How to get Drive Volume Name

  • Thread starter Thread starter Guest
  • Start date Start date
Chuck Walters said:
Is there a .net API to get the "Volume Name" of a given drive?

Use System.Management and WMI's class "Win32_LogicalDisk, something like
this will do...

using System.Management;

...

string drive= "c:";
string VolumeLabel = null;
string ObjectPath = String.Format("win32_LogicalDisk.DeviceId='{0}'",
drive);
using(ManagementObject mo = new ManagementObject(ObjectPath ))
{
mo.Get();
VolumeLabel = mo["VolumeName"];
}


Willy.
 
Back
Top