Getting the letter of a CD in VB.NET

I use the following code to get a list of letters for each drive on my computer. I want to get the drive letter from the CD from this list. How to check it?

The code I use to get the list is as follows:

In the Form.Load event:

  cmbDrives.DropDownStyle = ComboBoxStyle.DropDownList Dim sDrive As String, sDrives() As String sDrives = ListAllDrives() For Each sDrive In sDrives Next cmbDrives.Items.AddRange(ListAllDrives()) 

. ,.

 Public Function ListAllDrives() As String() Dim arDrives() As String arDrives = IO.Directory.GetLogicalDrives() Return arDrives End Function 
+4
source share
2 answers

Tested and returns the correct results on my computer:

 Dim cdDrives = From d In IO.DriveInfo.GetDrives() _ Where d.DriveType = IO.DriveType.CDRom _ Select d For Each drive In cdDrives Console.WriteLine(drive.Name) Next 

Suppose 3.5, of course, since it uses LINQ. To populate the list, change Console.WriteLine to ListBox.Items.Add.

+4
source
 For Each drive In DriveInfo.GetDrives() If drive.DriveType = DriveType.CDRom Then MessageBox.Show(drive.ToString()) Else MessageBox.Show("Not the cd or dvd rom" & " " & drive.ToString()) End If Next 
+1
source

Source: https://habr.com/ru/post/1343416/


All Articles