Use setupdigetclassdevs to enumerate Devices

Source: Internet
Author: User

Network
The code above is to use setupdigetclassdevs to enumerate the drive letter corresponding to the USB flash drive. In the code, the first way to determine whether the device is a USB flash drive is to use
Guid_devinterface_volume call setupdigetclassdevs and then
Setupdienumdeviceinterfaces, setupdigetdeviceinterfacedetail ...... Finally, we need to upload the information in advance.
Device ID comparison.

In fact, after testing, I found another simple method:

First, use
Setupdigetclassdevs enumerate guid_devinterface_usb_device and find all USB devices. Then use
Setupdigetclassdevs enumerate guid_devinterface_volume, find all volume, and recursively retrieve its parent
It can be reached by htree/root/0 or a parent is equal to the previous USB device.

It is worth noting that the devices named guid_devinterface_usb_device and guid_devinterface_disk have only one child, and they are themselves.

The following are some results of setupdigetclassdevs on my machine:

Volume

{4d36e965-e325-11ce-bfc1-08002be10318}
IDE/CDROMHL-DT-ST_CD-ROM_GCR-8523B_______________1.02 ____/5 & 4de3c4 & 0 & 0.0.0
{4d36e965-e325-11ce-bfc1-08002be10318}
SCSI/CDROM & ven_generic & PROD_DVD-ROM & rev_1.0/2 & 12b1de20 & 0 & 000
{71a27cdd-812a-11d0-bec7-08002be2092f}
Storage/removablemedia/7 & 35eac781 & 0 & RM
{71a27cdd-812a-11d0-bec7-08002be2092f}
Storage/volume/1 & 30a96598 & 0 & signature8150814offset27fcc3000length27fcb3400
{71a27cdd-812a-11d0-bec7-08002be2092f}
Storage/volume/1 & 30a96598 & 0 & signature8150814offset4ff97e200length4510e1e00
{71a27cdd-812a-11d0-bec7-08002be2092f}
Storage/volume/1 & 30a96598 & 0 & signature8150814offset7e00length27fcb3400

Disk

{4d36e967-e325-11ce-bfc1-08002be10318}
IDE/diskst340015a_________________________________ 3.15 ____/4c3548415848315020202020202020202020202020
{4d36e967-e325-11ce-bfc1-08002be10318}
Usbstor/disk & ven_generic & prod_usb_flash_drive & rev_1.00/6 & 2ecd5725 & 1

USB

{36fc9e60-c465-11cf-8056-444553540000}
USB/vid_1043 & pid_8012/5 & 1e5b5d9 & 0 & 5

Partition

{71a27cdd-812a-11d0-bec7-08002be2092f}
Storage/removablemedia/7 & 35eac781 & 0 & RM

Below are some volume parent levels:

{4d36e965-e325-11ce-bfc1-08002be10318}
IDE/CDROMHL-DT-ST_CD-ROM_GCR-8523B_______________1.02 ____/5 & 4de3c4 & 0 & 0.0.0
Pciide/idechannel/4 & 14e96d70 & 0 & 1
PCI/ven_8086 & dev_24db & subsys_300e103c & rev_02/3 & 13c0b0c5 & 0 & F9
ACPI/pnp0a03/1
Acpi_hal/pnp0c08/0
Root/acpi_hal/0000
Htree/root/0

{4d36e965-e325-11ce-bfc1-08002be10318}
SCSI/CDROM & ven_generic & PROD_DVD-ROM & rev_1.0/2 & 12b1de20 & 0 & 000
PCI/d1_prt/0000
Root/system/0003
Htree/root/0

{71a27cdd-812a-11d0-bec7-08002be2092f}
Storage/removablemedia/7 & 35eac781 & 0 & RM
Usbstor/disk & ven_generic & prod_usb_flash_drive & rev_1.00/6 & 2ecd5725 & 1
USB/vid_1043 & pid_8012/5 & 1e5b5d9 & 0 & 5
USB/root_hub20/4 & export bde3f & 0
PCI/ven_8086 & dev_24dd & subsys_300e103c & rev_02/3 & 13c0b0c5 & 0 & EF
ACPI/pnp0a03/1
Acpi_hal/pnp0c08/0
Root/acpi_hal/0000
Htree/root/0

{71a27cdd-812a-11d0-bec7-08002be2092f}
Storage/volume/1 & 30a96598 & 0 & signature8150814offset27fcc3000length27fcb3400
Root/ftdisk/0000
Htree/root/0

{71a27cdd-812a-11d0-bec7-08002be2092f}
Storage/volume/1 & 30a96598 & 0 & signature8150814offset4ff97e200length4510e1e00
Root/ftdisk/0000
Htree/root/0

{71a27cdd-812a-11d0-bec7-08002be2092f}
Storage/volume/1 & 30a96598 & 0 & signature8150814offset7e00length27fcb3400
Root/ftdisk/0000
Htree/root/0

You can find the following points worth noting:

1. The volume device ID in the IDE Hard Disk includes the volume location and length.
2. The volume parents in the IDE hard disk does not include the device ID of the hard disk.
3. The volume parents in the USB flash disk include the device ID of the USB flash disk.
4. The device ID of the volume in the USB flash disk is marked with "removablemedia ".

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.