Click here to Skip to main content
13,353,706 members (70,153 online)
Click here to Skip to main content
Add your own
alternative version


3 bookmarked
Posted 28 Jul 2013

How to determine the CD/DVD (optical) drive letter

, 28 Jul 2013
Rate this:
Please Sign up or sign in to vote.
How to use .NET Framework to determine the drive letter of the CD/DVD (optical) drive.


I needed to determine the drive letter of the DVD drive on a PC so that each user did not have to change the .config file to designate the drive letter. I found that the System.IO.DriveInfo.GetDrives() method did not return the optical drive when the drive was not ready. I searched the framework documentation and found another method that returned drive letters.


This example uses the System.Io.Directory.GetLogicalDrives() method to retrieve the configured drive letters. Then, it uses the System.IO.DriveInfo(driveName) method to return a DriveInfo object. The DriveInfo object has a DriveType property.

Using the code

The simple example can be inserted into a VB.NET program or converted to C# using one of the free code converters (e.g., developerFusion Convert VB.NET to C#[^]).

Dim strDVD as String
    Dim Drives As String() = System.IO.Directory.GetLogicalDrives
    For Each strDrive As String In Drives
        Dim di As System.IO.DriveInfo = _
            New System.IO.DriveInfo(strDrive.Substring(0, 1).ToUpper)
        If di.DriveType = System.IO.DriveType.CDRom Then ' Optical Drive (CD or DVD)
            strDVD = strDrive.Substring(0, 2) ' example: F:
        End If
Catch ex As Exception
    MsgBox("Error while trying to determine the DVD drive letter" & vbNewLine & vbNewLine & _
        ex.Message, MsgBoxStyle.Exclamation, "DVD Drive")
End Try


  • Version 1: July 28, 2013.


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


About the Author

Mike Meinz
United States United States
I’m retired. When I started my career, programming projects consisted of plugging wires into plug boards to create punch card processing applications to be run on electrical accounting machine like the IBM 402, 407, 085, 088, 514, 519, etc. From there, I moved to writing SPS and Autocoder applications on an IBM 1401 with 4K of memory eventually upgraded to 16K of memory. After many years of migrating my skills to various languages on various hardware platforms, I became an Information Technology Director where I didn’t need to program anymore. So, starting in 1996, I volunteered my time with a local community cable television organization and built some applications to help them run their operations. Originally in Clipper Summer 1987 and later Clipper 5.2, I migrated and enhanced those applications to VB .NET 2003 in 2003. I retired from my full-time job in 2010. Since then, I have continued to support the local community cable tv organization's applications. In 2013, I migrated the VB .NET 2003 Solution to VB .NET 2012 so that it can run on 64-bit computers and interact with Microsoft Office 2010. The upgrade went smoothly. In mid 2013, I developed a VB .NET 2012 application for them to download election results data from the Secretary of State's web site, format the results and send them to a VizRT character generator for on-air display.

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.180111.1 | Last Updated 28 Jul 2013
Article Copyright 2013 by Mike Meinz
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid