How do I detected whether a hard drive is connected via USB?

后端 未结 5 1566
无人及你
无人及你 2021-01-01 06:52

I am trying to write a little backup program for friends and family and want it to be as simple to use a possible. I don\'t want to have to ask the user where to backup thei

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-01 07:23

    I found a great function in the Win32 API for testing the type of drive.

    if( 2 == ::getDriveType(  )){
      // its removable 
    }
    

    Return values of function:

    DRIVE_UNKNOWN 0: The drive type cannot be determined.

    DRIVE_NO_ROOT_DIR 1: The root path is invalid; for example, there is no volume mounted at the specified path.

    DRIVE_REMOVABLE 2: The drive has removable media; for example, a floppy drive, thumb drive, or flash card reader.

    DRIVE_FIXED 3: The drive has fixed media; for example, a hard disk drive or flash drive.

    DRIVE_REMOTE 4: The drive is a remote (network) drive.

    DRIVE_CDROM 5: The drive is a CD-ROM drive.

    DRIVE_RAMDISK 6: The drive is a RAM disk.

    http://msdn.microsoft.com/en-us/library/windows/desktop/aa364939(v=vs.85).aspx

提交回复
热议问题