如何使用VB.NET格式化FAT 16格式的驱动器,无需用户交互

时间:2010-02-16 07:30:35

标签: vb.net format drive

如何在没有用户交互的情况下使用VB.NET格式化FAT 16格式的驱动器

1 个答案:

答案 0 :(得分:0)

这将是this C# answera similar question的VB.NET翻译:

Dim allDrives As DriveInfo() = DriveInfo.GetDrives()
For Each d As DriveInfo In allDrives
    If d.IsReady AndAlso (d.DriveType = DriveType.Removable) Then
        Dim startInfo As New ProcessStartInfo()
        startInfo.FileName = "format.com"
        startInfo.Arguments = "/fs:FAT /v:MyVolume /q " & d.Name.Remove(2)
        startInfo.UseShellExecute = False
        startInfo.CreateNoWindow = True
        startInfo.RedirectStandardOutput = True
        startInfo.RedirectStandardInput = True

        Dim p As Process = Process.Start(startInfo)

        Dim processInputStream As StreamWriter = p.StandardInput
        processInputStream.Write(vbCr & vbLf)


        p.WaitForExit()
    End If
Next