How to determine the drive property

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

How can I determine the drive property? I want to determine if it is a USB
drive, CF drive, etc and the manufacturer name. I am guessing that I would
call DeviceIOControl(). Where can I find the approciate control code and data
structure?

Thanks,

Frank
 
fchen,

Do you really need to mess with IOCTL codes?

There is much info you get from user mode API. Look in to the Volume Management Functions:
http://msdn.microsoft.com/library/en-us/fileio/base/volume_management_functions.asp (GetDriveType, GetVolumeInformation)

Also, pretty much all info you can get using WMI. Something like:
DiskDriveSet = GetObject("winmgmts:{impersonationLevel=impersonate}"). _
InstancesOf("Win32_DiskDrive")
will retrieve the disk drive collection for you. Properties DiskDriveSet(i).Manufacturer, DiskDriveSet(i).Model and
DiskDriveSet(i).MediaType would be what you are looking for.

Anyway, if you still need DeviceIoControl calls. Try IOCTL_DISK_GET_DRIVE_GEOMETRY, part of the retrieved "disk geometry" structure
will be the MediaType. Or just use IOCTL_STORAGE_GET_MEDIA_TYPES/IOCTL_STORAGE_GET_MEDIA_TYPES_EX.

As to the model/manufacturer/disk serial number and etc. info, some useful code you will find here:
http://www.winsim.com/diskid32/diskid32.cpp (look there for IDSECTOR structure, DFP_RECEIVE_DRIVE_DATA IOCTL code).

KM
 
Frank,

Read Konstantin's reply. Also USB is little specific and some approaches for obtaining infos are different. Since you mentioned only
basic info then you are ok, but in case that you need more info you should examine SetupApi functions.

Start By:
SetupDiGetClassDevs
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/setupdigetclassdevs.asp

With these and CM_ functions you can enumerate all drivers (devices) that you have working and installed in the past, and gather
infos from both registry and device itself. (Well more from registry but you can get handles to drivers).
Anyhow if you are interested in physical position of USB slot where disk is connected or some similar infos then you will have to
use SetupApi among other things.

You should also check devcon sample from DDK it will show you how to use these functions.

Regards,
Slobodan
 
Back
Top