Changing and setting drive lebels via C#
Could anyone out there provide some insight into how to alter drive labels via C# using WMI or something else?
To clarify, in an explorer window you will not that the C:\ drive for instance is normally labelled by default as "LOCAL DRIVE". I want to enumerate the drives on a local system, and apply specific labels to each one debending on their drive letter.
Craig MurphyPosted Feb 13, 2007, 4:19 AM
http://www.adaptiveintelligence.net/Developers/CodeSamples/DriveInfoClass.aspx
GeoffPosted Feb 12, 2007, 5:45 PM
Craig MurphyPosted Feb 12, 2007, 10:58 AM
The following code snippet should solve your problem:
using System;
using System.IO;
...
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
// If it's the D:\
if (d.Name == "D:\\")
{
Console.WriteLine("Drive {0}", d.Name);
Console.WriteLine(" File type: {0}", d.DriveType);
Console.WriteLine(" Volume label: {0}", d.VolumeLabel);
Console.WriteLine(" File system: {0}", d.DriveFormat);
// Change the drive name
if (d.IsReady == true)
{
d.VolumeLabel = "DATA1";
}
}
}
HTH