Article ID: 305184 - View products that this article applies to.
This article was previously published under Q305184
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:
The following file is available for download from the Microsoft Download Center:
Release Date: 08-Oct-2002
Download EnumCD.exe now
Collapse this imageExpand this image
For more information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:
119591Microsoft 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.
(http://support.microsoft.com/kb/119591/ )How to obtain Microsoft support files from online services
Collapse this tableExpand this table
Device enumerationThe 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 propertiesYou 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:
Windows Driver Development Kit: OverviewIOCTL_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 interfaceThe 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
Running the EnumCD.exe sampleThis sample does not require any arguments. Run the sample from a command prompt. Properties of all the CD drives will be listed.
Contact us for more help
Connect with Answer Desk for expert help.