Visual Basic 6.0可以通過調用API函數格式化一個磁盤,無論是軟盤還是硬盤。
打開一個新的項目(工程1) ,如果你沒有更改過缺省模式,那么Visual Basic 6.0會自動添加一個form1文件,在form1上添加一個命令控件,將下面的代碼拷入。
Option Explicit
Private Declare Function SHFormatDrive Lib"shell32"( ByVal Hend AS Long,ByVal Drive AS Long,ByVal FormatID AS Long,ByVal Options AS Long) as Long
Private Sub FormatDisk(intDrive as integer,blnQuickFormat as Boolean)
dim lngReturn As Long
if (blnQuickFormat) then
lngReturn= SHFormatDrive(0,intDrive,0&,1&)
else
lngReturn= SHFormatDrive(0,intDrive,0&,0&)
end if
end Sub
Private Sub Command1_Click()
call FormatDisk(0,True)
End Sub
運行此程序。
注意FormatDisk函數的第一個變量很重要,他的值是0,1,2時代表格式化的分別是:A、B、C盤。
標簽:
Visual
Basic
6.0
API
上傳時間:
2015-10-05
上傳用戶:kytqcool