- FormatDrive([driveleter], [filesystem], [quickformat], [clusterSize], [label], [enableCompression])
Tác giả: Sưu tầm
Mô tả: Format ổ đĩa dùng thư viện Management
Trước tiên các bạn Add Reference thư viện System.Management.
Rồi import System.Management
Thêm code:
- Public Function FormatDrive(ByVal driveLetter As String, Optional ByVal fileSystem As String = "NTFS", Optional ByVal quickFormat As Boolean = True, Optional ByVal clusterSize As Integer = 4096, Optional ByVal label As String = "", Optional ByVal enableCompression As Boolean = False) As Boolean
- If driveLetter.Length <> 2 OrElse driveLetter(1) <> ""c OrElse Not Char.IsLetter(driveLetter(0)) Then
- Return False
- End If
- 'query and format given drive
- Dim searcher As New ManagementObjectSearcher("Select * from Win32_Volume WHERE DriveLetter = '" & driveLetter & "'")
- For Each vi As ManagementObject In searcher.[Get]()
- vi.InvokeMethod("Format", New Object() {fileSystem, quickFormat, clusterSize, label, enableCompression})
- Next
- Return True
- End Function
Cách sử dụng:
Ví dụ
- FormatDrive("I", "NTFS", True, 4096, "BAO HIEP", False)