How can I determine the type of a particular drive?

后端 未结 3 399
予麋鹿
予麋鹿 2020-12-21 20:28

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 poss

相关标签:
3条回答
  • If you want to determine that a device is USB device, you can open its handle and send IOCTL queries using DeviceIoControl() to get bus type a device is connected to.

    EnumUsbDrivesLetters - the post is in Russian but it contains C++ source code, so the matter could be understood easily.

    Cheers, Andriy

    0 讨论(0)
  • 2020-12-21 21:01

    The only all-in-one API I know of for Windows with that information is WMI, but it's not terribly simple to use. On the other hand, many programs communicate with devices directly, using pass-through control codes, or I/O control codes like SMART_RCV_DRIVE_DATA.

    (I don't know how Speccy works, but I'm guessing it uses a combination of these methods to get the system info needed.)

    0 讨论(0)
  • 2020-12-21 21:07

    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.

    0 讨论(0)
提交回复
热议问题