1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
public static bool FormatDrive(string driveLetter,
string fileSystem = "NTFS",
bool quickFormat = true,
int clusterSize = 8192,
string label = "doByMakeKey",
bool enableCompression = false)
{
if (driveLetter.Length != 3 || driveLetter[1] != ':' || !char.IsLetter(driveLetter[0]))
return false;
ManagementObjectSearcher searcher = new ManagementObjectSearcher
(@"select * from Win32_Volume WHERE DriveLetter = '" + driveLetter + "'");
foreach (ManagementObject vi in searcher.Get())
{
vi.InvokeMethod("Format", new object[]
{ fileSystem, quickFormat,clusterSize, label, enableCompression });
}
return true;
} |