调用外壳的吧,function SHFormatDrive(hWnd : HWND;Drive, fmtID, Options : WORD) : longint; stdcall; external 'shell32.dll';
function _DiskFormat( const Drive : Char ):string; //对一个可移动驱动器或硬盘驱动器格式化
var
wDrive : WORD;
dtDrive : string;
formatretcode:longint;
begin
dtDrive := _DiskDriverType(Upcase(Drive));
if not _OK(dtDrive) then begin
result:=dtDrive+'(DiskFormat)'; exit;
end;
// if it's not a HDD or a FDD then raise an exception
if (not _Contain('可移动',dtDrive)) and (not _Contain('硬盘',dtDrive)) then
result := badresult+'无法格式化一个'+dtDrive
else begin// 进行格式化
wDrive := Ord( UpCase(Drive) ) - Ord( 'A' );
// SHFormatDrive 是一个没有公开的 API 函数调用
formatretcode:=SHFormatDrive( Application.Handle, wDrive, $ffff, 0);
if formatretcode=-1 then result:=badresult+'格式化程序已执行,在格式化中发生错误,返回代码:'+inttostr(formatretcode)
else if formatretcode=-2 then result:=badresult+'格式化程序已执行,用户放弃格式化驱动器:'+Drive
else if formatretcode=6 then result:='格式化程序已执行,完成驱动器:'+Drive+'的格式化'
else result:='格式化程序已执行,返回代码:'+inttostr(formatretcode);
end; // else
end;
function _DiskFormat( const Drive : Char ):string; //对一个可移动驱动器或硬盘驱动器格式化
var
wDrive : WORD;
dtDrive : string;
formatretcode:longint;
begin
dtDrive := _DiskDriverType(Upcase(Drive));
if not _OK(dtDrive) then begin
result:=dtDrive+'(DiskFormat)'; exit;
end;
// if it's not a HDD or a FDD then raise an exception
if (not _Contain('可移动',dtDrive)) and (not _Contain('硬盘',dtDrive)) then
result := badresult+'无法格式化一个'+dtDrive
else begin// 进行格式化
wDrive := Ord( UpCase(Drive) ) - Ord( 'A' );
// SHFormatDrive 是一个没有公开的 API 函数调用
formatretcode:=SHFormatDrive( Application.Handle, wDrive, $ffff, 0);
if formatretcode=-1 then result:=badresult+'格式化程序已执行,在格式化中发生错误,返回代码:'+inttostr(formatretcode)
else if formatretcode=-2 then result:=badresult+'格式化程序已执行,用户放弃格式化驱动器:'+Drive
else if formatretcode=6 then result:='格式化程序已执行,完成驱动器:'+Drive+'的格式化'
else result:='格式化程序已执行,返回代码:'+inttostr(formatretcode);
end; // else
end;
此函数在Delphi中没有封装,用Delphi改写后如下:
function SHFormatDrive(hwnd:hwnd;Drive:word;fmtID:word;Options:word):longint
其中参数Drive的取值如下:
0:格式化 A盘,1:格式化B盘,2:格式化C盘,以此类推;
参数fmtID一般取值0xFFFF
参数Options的取值及含义如下:
0:快速格式化
1:完全格式化
2:只复制文件系统
函数的返回值有三个,起取值如下:
-1 格式化出错
-2 格式化取消
-3 格式化没有完成。
调用方法前面的老兄已经写了。呵呵。
此函数在Delphi中没有封装,用Delphi改写后如下:
function SHFormatDrive(hwnd:hwnd;Drive:word;fmtID:word;Options:word):longint
其中参数Drive的取值如下:
0:格式化 A盘,1:格式化B盘,2:格式化C盘,以此类推;
参数fmtID一般取值0xFFFF
参数Options的取值及含义如下:
0:快速格式化
1:完全格式化
2:只复制文件系统
函数的返回值有三个,起取值如下:
-1 格式化出错
-2 格式化取消
-3 格式化没有完成。
调用方法前面的老兄已经写了。呵呵。