how do i format a hard drive?

tahu191

Well-known member
Joined
Oct 27, 2005
Messages
48
Location
USA
Programming Experience
Beginner
i need to make a program to be able to format a hard drive. how would i do this?
 
The easiest way:

VB.NET:
Sub FormatDrive(driveLetter As String)
    If MsgBox("Are you sure you want to format the " & driveLetter & ": drive?", MsgBoxStyle.Exclamation Or MsgBoxStyle.YesNo) = DialogResult.Yes Then
        Shell("format " & driveLetter & ":")
    End If
End Sub

Tweak arguments as desired to bypass the confirmations, etc.

Other more complex ways involve using the Shell32 SHFormatDrive Windows API (along with Kernel32's GetDriveType). But if all you need is a simple format and nothing else, this will get you started.

An example of the API method is here, thought it will need slight tweaking to be VB.NET friendly:
http://www.freevbcode.com/ShowCode.asp?ID=1371
 
Back
Top