v1.3 - 11 Sep 2012
numbers and cost
data capture utility
broadband and dial-up
Links to Other
Links to Other
Magenta Home Page
9th October 2018 - Sorry, you now need to request a
free file download password to access Delphi components.
Check Disk and Format Disk Component is a Delphi wrapper around the Windows APIs exported by fmifs.dll, which are used to
format fixed or removable disk drives and perform disk checks on Windows NT4 and later. It supports any local disk drive that
has been assigned a drive letter by Windows, just like the normal format and check disk tools in Windows.
The component may be used to format disks which are not currently in-use, and to verify the file system on any drives, but only
fix it on drives that are not in-use. It may be useful for preparing removable backup drives.
Supports exFAT for massive drives, if supported by the OS.
These fmifs.dll APIs are undocumented by Microsoft, but were reverse engineering by System Internals. The component is is based
on the command line Chkdskx and Formatx applications by Mark Russinovich available from
Please note that the fmifs.dll APIs are different from most other Windows APIs and are intended to be interactive with the user,
rather than passively accepting input and providing simple output. Specifically, they return progress information that is
normally seen in a Windows dialog or in a command line window, showing the steps being taken and reporting any errors or
corruption found. This component attempts to parse the messages and provide simple return information. A demo program
illustrates the use of all the functions.
Example progress doing Check Disk of a USB key. Note this varies depending on the file system type, and whether any errors are
Starting Check Disk for H:
H:\ Volume Label: USBH, File System: NTFS
Volume label is USBH.
CHKDSK is verifying files (stage 1 of 3)...
File verification completed.
CHKDSK is verifying indexes (stage 2 of 3)...
Index verification completed.
CHKDSK is verifying security descriptors (stage 3 of 3)...
Security descriptor verification completed.
Windows has checked the file system and found no problems.
253167 KB total disk space.
4 KB in 8 indexes.
0 KB in bad sectors.
3042 KB in use by the system.
2544 KB occupied by the log file.
250121 KB available on disk.
512 bytes in each allocation unit.
506335 total allocation units on disk.
500243 allocation units available on disk.
Check Disk: Finished OK
Example progress formatting a USB key.
Starting Format Disk for H:
H:\ Checking Existing Drive Format
H:\ Volume Label: USBH, File System: NTFS
H:\ Starting to Format Drive
Format Disk: Structure Created OK
Format Disk: Finished OK
H:\ Checking New Drive Format
H:\ Volume Label: USBKEY, File System: NTFS
H:\ New Volume Space: 256124416
The component may be installed on palette, but is non-visual so it's usually easier to create it in code.
TMediaType = (mtHardDisk, mtFloppy) ;
TFileSystem = (fsNTFS, fsFAT, fsFAT32, fsEXFAT) ;
LoadFmifs: boolean ;
Used to load the fmifs.dll APIs, the public variable MagFmifs_Loaded is set True if this succeeds. It's not necessary to call
this, since it's done before any other functions.
function FormatDisk (const DrvRoot: string; MediaType: TMediaType;
FileSystem: TFileSystem; const DiskLabel: string; QuickFormat: boolean;
ClusterSize: integer): boolean ;
This function causes a disk to be formatted. DvrRoot could be ie 'd:\'; MediaType is mtHardDisk or mtFloppy; FileSystem is
fsNTFS, fsFAT or fsFAT32; DiskLabel is up to 16 characters, the QuickFormat flag may cause faster formatting is overridden if
the file system changes; ClusterSize is 512, 1024, 2048, 4096, 8192, 16384, 32768 or 655536, but format may fail if it's not
supported by the file system.
Returns true if disk is formatted OK. Calls onInfoEvent with ASCII progress information and errors, see example above. Calls
onProgressEvent with step percentage completed, to optionally update a progress bar. Both events allow formatting to be
cancelled, but this may not be immediately effective. An exception will be raised if the drive can not be found or if it is
function CheckDisk (const DrvRoot: string; CorrectErrors, Verbose,
CheckOnlyIfDirty, ScanDrive: boolean): boolean ;
This function causes a disk check of the file system to be performed. DvrRoot could be ie 'd:\'; Correct Errors is true if the
disk can be written to correct errors; CheckOnlyIfDirty seems to be ignored; ScanDrive is true is a full disk scan should be
Returns true if check disk passes OK. The FileSysProblem will be true if a problem was detected during Check Disk with the
FirstErrorLine property containing the first error line, note this may not always be meaningful. The FreeSpaceAlloc property
will be true if 'free space marked as allocated' is seen, but this does not fail Check Disk. Calls onInfoEvent with ASCII
progress information and errors, see example above. Calls onProgressEvent with step percentage completed, to optionally update a
progress bar. Both events allow check disk to be cancelled, but this may not be immediately effective. An exception will be
raised if the drive can not be found or if it in-use and CorrectErrors is true.
function VolumeCompression (const DrvRoot: string; Enable: boolean): boolean ;
This function enables or disable volume compression, if the file system supports compression. DvrRoot could be ie 'd:\'.
Returns true if compression state is changed OK.
These are effectively results from Check Disk, see above.
property FileSysProblem: boolean ;
property FreeSpaceAlloc: boolean ;
property FirstErrorLine: string ;
These events are optional, but allow progress to be displayed or logged.
onProgressEvent - ProgressEvent (Percent: integer; var Cancel: boolean) ;
onInfoEvent - InfoEvent (Info: string; var Cancel: boolean) ;
A Windows demonstration application DISKFMT.EXE is supplied, with source and compiled program.
v1.1 - Better compatibility with Vista and later, no
longer shows an unknown Check Disk callback,
more callback messages handled. Also testing the
program has administrator rights on start-up with a warning if it will not
v1.2 - Supports Delphi 2009 and 2010, corrected progress
message charset which was OEM (IBM-PC) not ANSI
or Unicode, thanks to Francois Piette.
v1.2 - Updates subroutines for Win64 support.
v 1.3 - Added exFAT support for massive drives, if supported by the OS.
Added a Refresh Drives button to rebuild the drives box after changing
The Check Disk and Format Disk component is copyright by Magenta Systems
Ltd, but may be used freely.
Compatible with Delphi 7/2006/2007/2009/2010/XE/XE2/XE3, tested with Windows XP, 2003,
Vista, 2008, 7, 8 and 2012. Delphi 2009 and later versions supports Unicode.
Magenta Systems Ltd, 9 Vincent Road,
Croydon CR0 6ED, United Kingdom
Phone 020 8656 3636, International Phone +44 20 8656 3636
Copyright © 2018 Magenta Systems Ltd, England. All Rights Reserved.