OWL NExt - Knowledge Base

[ Home | Contents | Search | Next | Previous | Up ]

How to format a drive programmatically

Date: 12/1/99
Time: 10:22:24 PM

Question:

How do I format a drive programmatically?

Answer:

There is a semidocumented function ShFormatDrive that calls up the format dialog.

it uses the following constants:

// Standard Format Identifier
#define SHFMT_ID_DEFAULT = 0xFFFF;

// Option values
#define SHFMT_OPT_QUICKFORMAT = 0x0000;
#define SHFMT_OPT_FULL = 0x0001;
#define SHFMT_OPT_SYSONLY = 0x0002;

// Return values
#define SHFMT_ERROR = 0xFFFFFFFF;
#define SHFMT_CANCEL = 0xFFFFFFFE;
#define SHFMT_NOFORMAT = 0xFFFFFFFD;

extern "C" __declspec(dllimport) WINAPI
int SHFormatDrive(HWND hWnd, WORD Drive, int fmtID, WORD Options);

void TYourClass::Button1Click()
{
  SHFormatDrive(Handle,
                       0 /* Drive 'a:' */,
                       SHFMT_ID_DEFAULT,
                       OPTION_DEFAULT);
}

Last changed: July 14, 2001