Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleFormat a disk
Keywordsformat disk, format
CategoriesWindows, Utilities
 
Warning: This permanently erases all data from the disk! Do not format your hard drive unless you really want to lose everything.

Use the SHFormatDrive API function.

 
Private Sub FormatDisk(ByVal options As Long)
Dim drive_letter As String
Dim drive_num As Long
Dim status As Long

    drive_letter = UCase$(Left$(txtDrive.Text, 1))
    drive_num = Asc(drive_letter) - Asc("A")
    status = SHFormatDrive(hWnd, _
        drive_num, 0, options)
    Select Case status
        Case -1
            MsgBox "Format failed. User pressed Close."
        Case -2
            MsgBox "Format canceled. User pressed Close."
        Case -3
            MsgBox "Unable to format this disk."
        Case 6
            MsgBox "Disk formatted."
        Case Else
            MsgBox "Unknown return status " & _
                Format$(status)
    End Select
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated