|
|
|
SHFormatDrive is an undocumented but simple API function that allows you to format a drive. This function simply opens "Format Drive" diaolog window. Being undocument you won't find its Declare with the API Viewer utility: |
Click here to copy the following block | Private Declare Function SHFormatDrive Lib "Shell32.dll" (ByVal hWnd As Long, _ ByVal Drive As Integer, ByVal fmtID As Integer, ByVal Options As Integer) _ As Long |
The SHFormatDrive takes four parameters. The first is the handle of the parent window. The second is the index of the drive to be formatted (A=0, B=1, C=2 …). The third should always to be set to -1. The last parameter specifies the formatting options: 0 to quick format, 1 to full format or 2 to make a system disk. The function returns a value greater than 0 if it's successful, 0 if you pass invalid parameters, -1 if an error while formatting occurs, -2 if operation is aborted, and -3 if drive cannot be formatted. Here's the sample code: |
Click here to copy the following block | Private Sub btnFormatDrive_Click() Dim ret As Long ret = SHFormatDrive(Me.hWnd, cbDrive.ListIndex,-1, 1)
Select Case ret Case -1 MsgBox "Error during format operation" Case -2 MsgBox "Operation canceled by user" Case -3 MsgBox "This drive cannot be formatted" Case Else MsgBox "Done" End Select End Sub |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|