[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,
}
The fmtID field should always be passed SHFMT_ID_DEFAULT.
The drive field should denote the numerical listing of the drive letter to be formatted. (Ex: A is 0, Z is 25)
The options field should be 0 for a full disk format, pass SHFMT_OPT_FULL for a Quick Format, or set SHFMT_OPT_SYSONLY to create an MS-DOS System Boot Disk.
The function will return the ID of the last successful format, or one of the following error codes:
- SHFMT_ERROR: A general error occured while formatting. This is not an indication that the drive cannot be formatted though.
- SHFMT_CANCEL: The drive format was cancelled by user/OS.
- SHFMT_NOFORMAT: A serious error occured while formatting. The drive is unable to be formatted by the OS.
Please add some!
uint result = SHFormatDrive( this.Handle,
2, // formatting C:
(uint)SHFormatFlags.SHFMT_ID_DEFAULT,
0 ); // full format of C:
if ( result == SHFormatFlags.SHFMT_ERROR )
MessageBox.Show( "Unable to format the drive" );
Do you know one? Please contribute it!