C# 硬盘格式化

来源:百度知道 编辑:UC知道 时间:2024/06/23 21:56:44
用C#如何格式化指定盘符对应的硬盘(包括移动硬盘),望各位赐教,急急急,谢谢!
用C#编写格式化过程的目的主要是要把这个过程做成一个服务,让移动硬盘接入USB接口后自动完

c#中可以调用命令cmd命令
using System.IO;
using System.IO.Compression;

Process p = null;
p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
strOutput="format F: /FS:FAT32";
p.StandardInput.WriteLine(strOutput);
p.StandardInput.WriteLine("exit");
while (p.StandardOutput.EndOfStream)
{
strOutput = p.StandardOutput.ReadLine();
Console.WriteLine(strOutput);
}
p.WaitForExit();
p.Close();
======================================================
-----------------------格式化硬盘命令--------------------------
FORMAT volume [/FS:file-system] [/V:label] [/Q] [/A:size] [/C] [/X]
FORMAT volume [/V:label] [/Q] [/F:size]