Using DriveInfo class in VB.NET to get System Drives Information

Waqas Anwar
06 April 2008
14383 Views

DriveInfo class in .NET Framework is very useful class you can use to get information about the system drives. It has many properties and methods to query drive information such as drive type, drive format, total size or total free space. In the following Tutorial I will show you how to use this class in VB.NET Windows Application.

DriveInfo class





Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
    Dim drives As DriveInfo() = DriveInfo.GetDrives()
    For Each drive As DriveInfo In drives
        Me.comboBox1.Items.Add(drive.Name)
    Next
End Sub

Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim driveName As String = comboBox1.SelectedItem.ToString()
    Dim drive As New DriveInfo(driveName)
   
    label2.Text = "Drive Name: " + drive.Name
    label3.Text = "Volume Label: " + drive.VolumeLabel
    label4.Text = "Drive Type: " + drive.DriveType.ToString()
    label5.Text = "Drive Format: " + drive.DriveFormat
    label6.Text = "Total Size: " + (drive.TotalSize / 1024 / 1024 / 1024) + " GB"
    label7.Text = "Free Disk Space: " + (drive.TotalFreeSpace / 1024 / 1024 / 1024) + " GB"
    label8.Text = "Drive Ready: " + drive.IsReady.ToString()
End Sub