Detecting removable hard drive

Posted on 2007-08-09
Last Modified: 2013-11-25
How can I tall, using MS Visual C++ code, that a harddrive (F:, for instance) is removable (USB flash, for instance) or not?
Question by:olegsp
    LVL 5

    Expert Comment

    Its simple:o)
    well maybe not quite
    you need to use SetupDiXXX class of functions

    use SetupDiGetClassDevs to enumerate devices of certain class
    examine content of
    devguid.h    // Device guids
    setupapi.h   // SetupDiXXX
    header files

    if that will help - here is MS knowledge base sample on how to enumerate CD-ROM drives and their properties

    This should give you basic idea - or will scare you off  :o)

    Ask me if you need further help

    Accepted Solution

    UINT drivetype;
          switch(::GetDriveType(DrivePath)) \\ e.g., DrivePath="F:\\"
          case 0: // The drive type cannot be determined.
          case 1: // The root directory does not exist.
                drivetype = 1;
          case DRIVE_REMOVABLE: // The drive can be removed from the drive.
                drivetype = 2;
          case DRIVE_CDROM: // The drive is a CD-ROM drive.
          case DRIVE_FIXED: // The disk cannot be removed from the drive.
                drivetype = 3;
          case DRIVE_REMOTE: // The drive is a remote (network) drive.
                drivetype = 4;
          case DRIVE_RAMDISK: // The drive is a RAM disk.
                drivetype = 5;

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    As hardware bugs go, this is a strange one! I upgraded a laptop in December 2011 with a 512GB Crucial m4 2.5-inch/9.5mm SATA Solid State Drive (SSD), Crucial part number CT512M4SSD2: …
    Ever notice how you can't use a new drive in Windows without having Windows assigning a Disk Signature?  Ever have a signature collision problem (especially with Virtual Machines?)  This article is intended to help you understand what's going on and…
    This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now