VB如何格式化硬盘?

来源:百度知道 编辑:UC知道 时间:2024/05/13 05:29:48
我记得有好像可以是用shell调用format.com:但是具体内容我忘了。

用以下代码可以调用Windows的格式化窗口来格式化指定的磁盘:
Private Const SHFMT_ID_DEFAULT = &HFFFF&
Private Declare Function SHFormatDrive Lib "shell32.dll" (ByVal hWnd As Long, ByVal Drive As Long, fmtID As Long, Options As Long) As Long
'---rive参数为0时指A盘,1指B盘,2指C盘,以此类推
Private Sub Command1_Click()
Dim lret As Long
lret = SHFormatDrive(Me.hWnd, 0, SHFMT_ID_DEFAULT, 0)
Select Case lret
Case -2
MsgBox "OK !"

Case -3
MsgBox "Cannot format a read only drive !"
End Select
End Sub