.NET Framework中是否有任何库允许我们创建,删除&在.NET中以编程方式擦除磁盘分区? (我使用的是VB.NET)
目前我正在使用的选项是通过dos命令'diskpart',我觉得在编码观点上效率不高。
答案 0 :(得分:2)
试试这个......
Imports System.Text
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Try
Dim partitionLetter As String = "Q"
Dim sb As StringBuilder = New StringBuilder()
sb.AppendLine("SELECT DISK=0") 'Select the first disk drive
sb.AppendLine("CREATE PARTITION PRIMARY") 'create new partition
sb.AppendLine("ASSIGN LETTER=" + partitionLetter) 'assign letter
sb.AppendLine("FORMAT FS=FAT32 LABEL=""FD"" QUICK") 'format new partition
sb.AppendLine("EXIT")
System.IO.File.WriteAllText("c:\part.scr", sb.ToString()) 'create diskpart script
Process.Start("diskpart.exe", "/s c:\part.scr") 'run the script
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
End Class