Answers for "burning cd/dvd images to usb"

0

burning cd/dvd images to usb

Imports System.IO
Imports System.Text

Public Class Form1

    Private sourceFile As FileInfo

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
        RefreshDrives()
    End Sub

    Private Sub btnBrowse_Click(ByVal sender As Object, ByVal e As EventArgs) _
        Handles btnBrowse.Click
        Using ofd As New OpenFileDialog
            ofd.Title = "Select disk image file"
            ofd.Multiselect = False
            Dim result As DialogResult = ofd.ShowDialog
            If result = Windows.Forms.DialogResult.OK Then
                Try
                    sourceFile = New FileInfo(ofd.FileName)
                Catch ex As Exception
                    MessageBox.Show(ex.Message)
                    sourceFile = Nothing
                End Try
            End If
        End Using
        If sourceFile IsNot Nothing Then
            Me.TextBox1.Text = sourceFile.ToString
        End If
        RefreshBtn_Nuke()
    End Sub

    Private Sub btnRefresh_Click(ByVal sender As Object, ByVal e As EventArgs) _
        Handles btnRefresh.Click
        RefreshDrives()
    End Sub

    Private Sub RefreshDrives()
        Me.ComboBox1.Items.Clear()
        For Each di As DriveInfo In DriveInfo.GetDrives
            If di.DriveType = DriveType.Removable Then
                Me.ComboBox1.Items.Add(di)
            End If
        Next
        Me.ComboBox1.SelectedIndex = 0
        RefreshBtn_Nuke()
    End Sub

    Private Sub RefreshBtn_Nuke()
        btnNuke.Enabled = (sourceFile IsNot Nothing) AndAlso _
            Me.ComboBox1.Items.Count > 0
    End Sub

    Private Sub btnNuke_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnNuke.Click
        Dim result As DialogResult
        Dim drive As String = Me.ComboBox1.Text
        Dim sb As New StringBuilder
        sb.AppendLine("Do you really want to erase drive " & drive & "?")
        sb.AppendLine("Doing so will DESTROY ALL EXISTING DATA ON DRIVE " & drive & "!")
        result = MessageBox.Show(sb.ToString, _
                                 "Destroy Drive " & drive & " ?", _
                                 MessageBoxButtons.YesNo, _
                                MessageBoxIcon.Exclamation, _
                                 MessageBoxDefaultButton.Button2)
        If result = Windows.Forms.DialogResult.Yes Then
            Dim dest As DriveInfo = TryCast(Me.ComboBox1.SelectedItem, DriveInfo)
            If sourceFile IsNot Nothing AndAlso dest IsNot Nothing Then
                Dim written As Integer = Win32.CopyToDevice(sourceFile, dest)
                MessageBox.Show("Wrote: " & written & " bytes to " & drive, "Done", _
                                MessageBoxButtons.OK, MessageBoxIcon.Information)
                Application.Exit()
            Else
                RefreshBtn_Nuke()
            End If
        End If
    End Sub

End Class
Posted by: Guest on June-05-2021

Browse Popular Code Answers by Language