Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7579071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:35:04+00:00 2026-05-30T17:35:04+00:00

I am trying to figure out how to detect if a drive is a

  • 0

I am trying to figure out how to detect if a drive is a mass storage device. I can get the drive letters but cannot figure out how to detect what sort of device it is. I am trying to detect if a Garmin GPS receiver is connected to a PC in mass storage mode.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T17:35:05+00:00Added an answer on May 30, 2026 at 5:35 pm

    You can use the WMI for this task, exist several classes which can help you to determine that information, start with the Win32_USBHub checking for the value Mass Storage Device in the the property Description, also take a look in the Win32_PNPEntity class. If you don’t have experience accesing the WMI from Delphi, try using the Wmi delphi code creator

    UPDATE

    To associate the values returned by the Win32_USBHub or Win32_USBControllerDevice WMI classes with a Disk Drive letter, you must follow the next steps

    1. Query for the Win32_USBControllerDevice class.
    2. Using the DeviceID extracted of the dependent property of each returned instance(record) check the Win32_PnPEntity class loinked to a Win32_DiskDrive using a WQL sentence like so : ASSOCIATORS OF {Win32_PnPEntity.DeviceID="DeviceID"} WHERE ResultClass = Win32_DiskDrive
    3. Now using Win32_DiskDriveToDiskPartition class you can found the link between the Disk Drive and the partition.
    4. Finally using the Win32_LogicalDiskToPartition class you can extract the Drive letter.

    Check this sample code

    {$APPTYPE CONSOLE}
    
    {$R *.res}
    
    uses
      Types,
      StrUtils,
      SysUtils,
      ActiveX,
      ComObj,
      Variants;
    
    procedure ScanUSBPnpDevices;
    const
      wbemFlagForwardOnly = $00000020;
    var
      FSWbemLocator  : OLEVariant;
      objWMIService  : OLEVariant;
    
      USBControllerDevices: OLEVariant;
      USBControllerDevice : OLEVariant;
      EnumUSBDevice       : IEnumvariant;
    
      PnPEntities         : OLEVariant;
      PnPEntity           : OLEVariant;
      EnumPnPEntity       : IEnumvariant;
    
      DiskDrives          : OLEVariant;
      DiskDrive           : OLEVariant;
      EnumDiskDrive       : IEnumvariant;
    
      DiskPartitions      : OLEVariant;
      DiskPartition       : OLEVariant;
      EnumDiskPartition   : IEnumvariant;
    
      iValue         : LongWord;
      DeviceID       : string;
      DiskDeviceID   : string;
      DiskPartID     : string;
    
      StringDynArray : TStringDynArray;
    begin;
      FSWbemLocator   := CreateOleObject('WbemScripting.SWbemLocator');
      objWMIService   := FSWbemLocator.ConnectServer('localhost', 'root\CIMV2', '', '');
      //This will scan all the usb device, you can filter this WQL sentece using any property of this class, to speed-up the process.
      USBControllerDevices := objWMIService.ExecQuery('SELECT Dependent FROM Win32_USBControllerDevice','WQL',wbemFlagForwardOnly);
      EnumUSBDEvice        := IUnknown(USBControllerDevices._NewEnum) as IEnumVariant;
      while EnumUSBDEvice.Next(1, USBControllerDevice, iValue) = 0 do
      begin
        StringDynArray:=SplitString(USBControllerDevice.Dependent, '=');
        DeviceID:=StringDynArray[1];
        Writeln(Format('USB Controller Device Device ID %s',[DeviceID]));
        PnPEntities     := objWMIService.ExecQuery(Format('ASSOCIATORS OF {Win32_PnPEntity.DeviceID=%s} WHERE ResultClass = Win32_DiskDrive',[DeviceID]),'WQL',wbemFlagForwardOnly);
        EnumPnPEntity   := IUnknown(PnPEntities._NewEnum) as IEnumVariant;
        while EnumPnPEntity.Next(1, PnPEntity, iValue) = 0 do
        begin
          //Escape the `\` chars in the DeviceID value because the '\' is a reserved character in WMI.
          DiskDeviceID   := PnPEntity.DeviceId;
          Writeln(Format('  Disk Drive Device ID %s',[DiskDeviceID]));
          DiskDeviceID   := StringReplace(DiskDeviceID,'\','\\',[rfReplaceAll]);;
          DiskDrives     := objWMIService.ExecQuery(Format('ASSOCIATORS OF {Win32_DiskDrive.DeviceID="%s"} WHERE AssocClass = Win32_DiskDriveToDiskPartition',[DiskDeviceID]),'WQL',wbemFlagForwardOnly);
          EnumDiskDrive  := IUnknown(DiskDrives._NewEnum) as IEnumVariant;
          while EnumDiskDrive.Next(1, DiskDrive, iValue) = 0 do
          begin
            DiskPartID:=DiskDrive.deviceID;
            Writeln(Format('    Disk Partition ID %s',[DiskPartID]));
            DiskPartitions:=objWMIService.ExecQuery(Format('ASSOCIATORS OF {Win32_DiskPartition.DeviceID="%s"} WHERE AssocClass = Win32_LogicalDiskToPartition',[DiskPartID]),'WQL',wbemFlagForwardOnly);
            EnumDiskPartition  := IUnknown(DiskPartitions._NewEnum) as IEnumVariant;
            while EnumDiskPartition.Next(1, DiskPartition, iValue) = 0 do
            begin
               Writeln(Format('      Drive Letter %s',[String(DiskPartition.DeviceID)]));
               DiskPartition:=Unassigned;
            end;
            DiskDrive:=Unassigned;
          end;
          PnPEntity:=Unassigned;
        end;
        USBControllerDevice:=Unassigned;
      end;
    end;
    
    begin
     try
        CoInitialize(nil);
        try
          ScanUSBPnpDevices;
        finally
          CoUninitialize;
        end;
     except
        on E:Exception do
            Writeln(E.Classname, ':', E.Message);
     end;
      Readln;
    end.
    

    Which will return some thing like this.

    USB Controller Device Device ID "USBSTOR\\DISK&VEN_HP&PROD_V100W&REV_1.00\\3S980
    62800DD&0"
      Disk Drive Device ID \\.\PHYSICALDRIVE1
        Disk Partition ID Disk #1, Partition #0
          Drive Letter F:
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to figure out how I can detect the visitor's location, so
I'm trying to figure out how to write a regex that can detect if
I'm trying to figure out how to detect when the current user has changed
Trying to figure out how I can do this properly. The print_r looks like
I'm trying to figure out how I could detect whether people logging into my
I'm trying to figure out a way to reliably detect if a channel is
I'm trying to figure out how to detect whether a binary has been compressed
I'm trying to figure out a regular expression that will detect if there is
I'm trying to figure out how to get the current space # from mission
So I was trying to figure out how to detect the number of operands

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.