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

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source