3

How to format drive in FAT 16 format using VB.NET without user interaction

Matthieu
  • 4,605
  • 4
  • 40
  • 60
amita
  • 31
  • 1
  • 2
  • 2
    Without even a warning message "are you sure?" Format what *kind* of drive? – pavium Feb 16 '10 at 07:44
  • Its USB drive, its user requirement after successful copy of files, it should format drive to FAT 16 without any user interaction – amita Feb 16 '10 at 09:25
  • Can anyone help please on this issue? – amita Feb 17 '10 at 09:35
  • This has already been asked and answered, only in C#: http://stackoverflow.com/questions/1232398/how-to-programically-format-sd-card-on-fat16-on-windows-net – Helen Feb 20 '10 at 20:14
  • But it does not work for vb.net – amita Feb 26 '10 at 07:56
  • @amita : I answered with a translation of the c# code. Can you point out what is not working in it if you still have an issue with this code ? It seems to be working fine for me. – Matthieu Sep 14 '11 at 16:00

1 Answers1

0

That would be the VB.NET translation of this C# answer to a similar question :

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
Community
  • 1
  • 1
Matthieu
  • 4,605
  • 4
  • 40
  • 60