You could use pinvoke to call SHFormatDrive.
[DllImport("shell32.dll")]
static extern uint SHFormatDrive(IntPtr hwnd, uint drive, uint fmtID, uint options);
public enum SHFormatFlags : uint {
SHFMT_ID_DEFAULT = 0xFFFF,
SHFMT_OPT_FULL = 0x1,
SHFMT_OPT_SYSONLY = 0x2,
SHFMT_ERROR = 0xFFFFFFFF,
SHFMT_CANCEL = 0xFFFFFFFE,
SHFMT_NOFORMAT = 0xFFFFFFD,
}
//(Drive letter : A is 0, Z is 25)
uint result = SHFormatDrive( this.Handle,
6, // formatting C:
(uint)SHFormatFlags.SHFMT_ID_DEFAULT,
0 ); // full format of g:
if ( result == SHFormatFlags.SHFMT_ERROR )
MessageBox.Show( "Unable to format the drive" );
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…