Finding removable drive type(CD or DVD) in Windows

The heart of the following code snippet is DeviceIoControl Win32 function and IOCTL_STORAGE_GET_MEDIA_TYPES_EX control code(used to get the media types).
The documentation provided in MSDN for the usage of IOCTL_STORAGE_GET_MEDIA_TYPES_EX is really hopeless. There isn’t much to explain in the code.

  1. Enumerate each drive (using bit vector returned by GetLogicalDrives)
  2. Determine if the drive is a removeable drive(using GetDriveType)
  3. Open removable device(using CreateFile function) and pass the device handle to DeviceIoControl. ** the buffer passed to DeviceIoControl function must be big enough hold DEVICE_MEDIA_INFO ** (MSDN really sucks)
  4. Finally examine the mediaTypes->DeviceType value.


Hope it helps you. Comment on it.

Leave a comment

Leave a Reply