vbpslogo2.gif (19593 bytes)
Brad's VB-32 Programs & Samples

Posted: 06/26/97, last update: 06/26/97

Home

The undocumented SHFormatDrive function

I keep seeing people ask about this function so I thought I'd take a shot at it. This is as far as I got verifying the info floating around the Deja News database at http://www.dejanews.com/ Because at the time of this writing the function is not documented by MS, I'm assuming the info found there was obtained through trial and error. I definitely confirmed the info below through my own trial and error, and suggest you verify everything for yourself as well. The parameter and constant names are obviously a result of personal preference.

Note:

This function behaves differently on Win95 & WinNT4 (see the iCapacity, iFormatType & return value descriptions). The Win95 implementation seems OK. But considering the different dialog options on WinNT, and that I'm running it on the FAT file system & with no compression, other parameter values may be available.

Overview:

The SHFormatDrive brings up the system-defined Format dialog box and selects specified options....
Declare Function SHFormatDrive Lib "shell32" _
                            (ByVal hwndOwner As Long, _
                             ByVal iDrive As Long, _
                             ByVal iCapacity As Long, _
                             ByVal iFormatType As Long) As Long
Parameter Description
hwndOwner Handle of the owner window for the dialog box.
iDrive Value specifying the zero-based system drive index (A = 0, B = 1, etc.)
iCapacity Value specifying the formatted capacity of the drive; the corresponding item is selected in the Capacity combo box.
Win95:
SHFD_CAPACITY_DEFAULT = 0  'default drive capacity
SHFD_CAPACITY_360 = 3           ' 360KB, applies to 5.25" drives only
SHFD_CAPACITY_720 = 5           ' 720KB, applies to 3.5" drives only

WinNT(?):

...?
iFormatType Value specifying the format operation, the corresponding option button is selected in the Format type group box.
Win95:
SHFD_FORMAT_QUICK = 0        ' quick format
SHFD_FORMAT_FULL = 1          ' full format
SHFD_FORMAT_SYSONLY = 2  ' copies system files only

WinNT(?):

SHFD_FORMAT_FULL = 0      ' full format
SHFD_FORMAT_QUICK = 1    ' quick format

Return values

Win95:
-3 failure, drive can't be formatted (either doesn't exist or contains files in use by Windows)
-2 operation cancelled
-1 operation attempted but completed unsuccessfully
6(?) operation completed successfully
    
WinNT:
-1 dialog was shown
0 error, dialog not shown

SHFormatDrive can also be passed to rundll32 and run from a command line via:

rundll32.exe shell32.dll,SHFormatDrive

but it's command line parameters don't seem to be recognized.