【问题标题】:Programmatically create/delete/wipe disk partition?以编程方式创建/删除/擦除磁盘分区?
【发布时间】:2013-06-28 03:53:32
【问题描述】:

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

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

【问题讨论】:

标签: .net vb.net disk disk-partitioning


【解决方案1】:

试试这个...

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

【讨论】:

    猜你喜欢
    • 2011-01-28
    • 1970-01-01
    • 2012-01-31
    • 1970-01-01
    • 1970-01-01
    • 2019-02-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多