Visual Basic可以通過調用API函數格式化一個磁盤,無論是軟盤還是硬盤。
打開一個新的項目(project1) ,如果你沒有更改過缺省模式,那么Visual Basic會自動添加一個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盤。
注意:讀者使用此程序作練習的時候千萬不要用硬盤作實驗,筆者不為可能發生的錯誤和損失負責。
延伸閱讀
文章來源于領測軟件測試網 http://www.kjueaiud.com/