0

.NET Framework 中是否有任何库允许我们在 .NET 中以编程方式创建、删除和擦除磁盘分区?(我正在使用 VB.NET)

目前我使用的选项是通过dos命令'diskpart',我觉得从编码的角度来看效率不高。

4

1 回答 1

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
于 2015-01-07T13:18:07.190 回答