Click here to Skip to main content
15,900,378 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,
I am using following code to get Drive letter list in my computer. I want to get the drive letter of CD Drive from this list. Please advise how to check it.

The code I am using to get list is as below:

In 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

Thanks
Furqan

[edit]Code block added, "Ignore HTML..." option disabled - OriginalGriff[/edit]
Posted
Updated 11-Mar-11 20:29pm
v2

<pre lang="vb">
Dim CDPath as String
Private Sub Form_Load()
Dim fso As New Scripting.FileSystemObject
Dim drv As Drive
For Each drv In fso.Drives
     If drv.DriveType = CDRom Then
          CDPath = drv.Path
          Exit For
     End If
Next drv
Set drv = Nothing
Set fso = Nothing
End Sub

 
Share this answer
 
Comments
Furqan Sehgal 12-Mar-11 4:59am    
Does not recognize
Scripting.FileSystemObject
Try:
VB
Public Enum DriveType As Integer
    Unknown = 0
    NoRoot = 1
    Removable = 2
    Localdisk = 3
    Network = 4
    CD = 5
    RAMDrive = 6
End Enum

<DllImport("kernel32.dll", CharSet := CharSet.Auto)> _
Public Shared Function GetDriveType(lpRootPathName As String) As Integer
End Function
Private Shared Sub Main(args As String())
    Console.WriteLine("Started")

    Dim drives As String() = Directory.GetLogicalDrives()
    For Each drive As String In drives
        Dim type As DriveType = CType(GetDriveType(drive), DriveType)
        Console.WriteLine(drive & " is a " & type.ToString())
    Next

    Console.WriteLine(&quot;Stopped&quot;)
    Console.ReadLine()
End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900