c++windowswinapihardwaregetdrivetype

How can I determine the type of a particular drive?


I feel somewhat noob yet with this of getting the Information of Hardware of the CPU, so i come with this request: Hard Drive, CD/DVD/Bluray reader, Floppy and if it's possible USB. I've been looking on MSDN GetDriveType but seems i'm bad at searching or i don't understand it. Any idea?


Solution

  • I'm not sure what you didn't understand about the documentation you linked to...

    The sole argument accepted by the function is the root directory of the drive you want to get information about (including a trailing backslash). The function returns a value indicating which type of drive that is. A chart is shown that gives the possible return values and what each of them mean.

    For example:

    GetDriveType(_T("C:\\"))    // returns DRIVE_FIXED if C:\ is my hard drive
    GetDriveType(_T("A:\\"))    // returns DRIVE_REMOVABLE if A:\ is my floppy drive
    GetDriveType(_T("D:\\"))    // returns DRIVE_CDROM if D:\ is a CD-ROM drive
    GetDriveType(_T("N:\\"))    // returns DRIVE_REMOTE if N:\ is a network drive
    

    It also says that if you want to determine whether a drive is a USB-type drive, you need to call the SetupDiGetDeviceRegistryProperty function and specify the SPDRP_REMOVAL_POLICY property.