Public Function FormatDrive(ByVal DriveLetter As String, _
Optional PermitNonRemovableFormat As Boolean = False) As _
Boolean
Dim sDrive As String
Dim lDrive As Long
Dim iDriveType As Integer
Dim iAns As Integer
Dim sDriveLetter
Dim lRet As Long
sDrive = UCase(DriveLetter)
sDriveLetter = sDrive
If Len(sDrive) = 1 Then sDriveLetter = sDriveLetter & ":\"
If Len(sDrive) = 2 And Right$(sDrive, 1) = ":" _
Then sDriveLetter = sDrive & "\"
lDrive = Asc(Left(sDrive, 1)) - 65
iDriveType = DriveType(sDrive)
Select Case iDriveType
Case 2
lRet = SHFormatDrive(Me.hWnd, lDrive, HFFFF, FORMAT_FULL)
FormatDrive = lRet = 0
Case 3, 4, 5, 6
If Not PermitNonRemovableFormat Then Exit Function
lRet = SHFormatDrive(Me.hWnd, lDrive, HFFFF, FORMAT_FULL)
FormatDrive = lRet = 0
Case Else 'no such drive
Exit Function
End Select
End Function
Private Function DriveType(Drive As String) As Integer
Dim sAns As String, lAns As Long
If Len(Drive) = 1 Then Drive = Drive & ":\"
If Len(Drive) = 2 And Right$(Drive, 1) = ":" _
Then Drive = Drive & "\"
DriveType = GetDriveType(Drive)
End Function