How to enumerate CD drives and get their properties/capabilities

Article translations Article translations
Article ID: 305184 - View products that this article applies to.
This article was previously published under Q305184
Expand all | Collapse all

On This Page

SUMMARY

Win32 applications can use the SetupDixxx APIs to enumerate all of the devices that are available on a computer.

The EnumCD sample provided by means of this article does the following:
  • Demonstrates SetupDixxx by enumerating all the CD drives regardless of their bus type.
  • Obtains a handle to the device to send IOCTL commands to get the adapter and device properties.
  • Uses SCSI pass-through commands to get the inquiry data and the drive capabilities.
Note You can obtain drive capabilities only for drives that support SCSI-3 multimedia commands (MMC).

MORE INFORMATION

The following file is available for download from the Microsoft Download Center:
Collapse this imageExpand this image
Download
Download EnumCD.exe now
Release Date: 08-Oct-2002

For more information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:
119591 How to obtain Microsoft support files from online services
Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help prevent any unauthorized changes to the file. The EnumCD.exe file contains the following files.
Collapse this tableExpand this table
File nameDescription
EnumCD.cimplements the Win32 application to enumerate the CD drives
EnumCD.hheader file for EnumCD.c
EnumCD.htmdocumentation for these samples (this file)
EnumCD.exeWindows 2000 executable program (free build)
SourcesDDK build instructions

Device enumeration

The EnumCD sample uses the device Setup class GUID (globally unique identifier) GUID_DEVCLASS_CDROM to enumerate all the CD drives that are installed on the computer. The sample then obtains the device ID by getting the registry properties.

To send IOCTLs from a Win32 application, you must have the handle of the device. To obtain the device handle, use the device interface name to open the device. The CD-ROM class driver exposes this interface by registering the device interface. It uses the CdRomClassGuid interface GUID for device registration.

A Win32 application can obtain all the registered CD-ROM interfaces by using the SetupDixxx APIs with the same interface GUID in a loop. Because the interface registration is done by the CD-ROM class driver, this technique works for all types of CD drives, such as SCSI, IDE, USB, and 1394.

Device properties

You can use IOCTL_STORAGE_QUERY_PROPERTY to get the adapter and device properties. This IOCTL takes the STORAGE_PROPERTY_QUERY data structure as an argument. However, before you call IOCTL_STORAGE_QUERY_PROPERTY, you must correctly set the STORAGE_PROPERTY_ID and STORAGE_QUERY_TYPE members.

The STORAGE_PROPERTY_ID determines the property to be returned. Set it to either StorageAdapterProperty or StorageDeviceProperty:
  • StorageAdapterProperty returns the STORAGE_ADAPTER_DESCRIPTOR data structure, which contains adapter properties such as the bus type, maximum transfer length, alignment mask, and others.
  • StorageDeviceProperty returns the STORAGE_DEVICE_DESCRIPTOR data structure, which contains the device type, vendor ID, product ID, and others. This information is obtained from the respective port drivers.
For more information about this IOCTL and data structures, visit the following Web site:
Windows Driver Development Kit: Overview
http://www.microsoft.com/whdc/devtools/ddk/default.mspx/
IOCTL_STORAGE_GET_MEDIA_TYPES_EX is used to get information about types of media supported by a CD drive (whether it is a CD-ROM or DVD drive). It does not tell whether it is a reader/writer, or what types of discs it supports. However, you can obtain this information from the Mode Sense page.

SCSI pass-through interface

The device handle obtained is also used to send SCSI pass-through commands to the device. The sample sends the Inquiry command to the device to get the Inquiry data.

The sample also sends a Mode Sense command to read the "CD Capabilities and Mechanical Status" parameter page from the device. This page contains (among other things) information about the capabilities of the CD drive, including whether it is a CD or DVD drive, whether it supports reading or writing, and the media types it supports (such as CD-R/RW or DVD-ROM/R/RAM). As mentioned earlier, this parameter page is defined only in the SCSI-3 MMC specification. Devices that do not support this specification will return an error.

For more information about the SCSI pass-through interface, see the SPTI sample, which is available in the Windows 2000 DDK.

Building the sample

  1. Under the Development Kits program group, click either the Free Build Environment icon or the Checked Build Environment icon to set the basic environment variables that are needed by the Build utility.
  2. Change to the folder that contains the device source code, for example:
    cd c:\EnumCD
  3. Run the Build utility: either type build -ceZ, or use the BLD macro.

    This method invokes the Microsoft Make routines that produce log files named as follows (where xxx is "fre" or "chk", depending on the environment you choose) if there are any warnings or errors:
    • Buildxxx.log
    • Buildxxx.err
    • Buildxxx.wrn
    Note If the build succeeds, the executable EnumCD.exe file is placed in a platform-specific subfolder of your TargetPath folder that is specified in the Sources file.

Running the EnumCD.exe sample

This sample does not require any arguments. Run the sample from a command prompt. Properties of all the CD drives will be listed.

Properties

Article ID: 305184 - Last Review: November 23, 2005 - Revision: 3.1
APPLIES TO
  • Microsoft Win32 Device Driver Kit for Windows 2000
  • Microsoft Windows XP Driver Development Kit
  • Microsoft Windows Server 2003 Driver Development Kit
Keywords: 
kbhowto kbstoragedev kbfile KB305184

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com