meoit

Distinguish between USB Fixed Disk and an External HDD.

16 posts in this topic

#1 ·  Posted

Hello all.

I have two devices: one USB Fixed Disk (not Removable Disk), one External HDD (HDD-Box, maybe SSD-Box). They are plugged in my Laptop via USB Port.

I use DriveGetType('X:', $DT_DRIVETYPE) --> result Fixed

DriveGetType('Y:', $DT_DRIVETYPE) --> result Fixed

I use DriveGetType('X:', $DT_BUSTYPE) --> result USB

DriveGetType('Y:', $DT_BUSTYPE) --> result USB

X: = my USB Fixed Disk (not Removable Disk)

Y: = my External HDD (HDD-Box)

They give same result. :)

How can I distinguish between us ?.

Thanks for support.

Share this post


Link to post
Share on other sites



#2 ·  Posted

I only have a USB thumb drive but see what this does

#include <Array.au3>

_DrivesFromBusType("")

Func _DrivesFromBusType($sBus = Default)
    Local $objWMIService = ObjGet("winmgmts:\\.\root\cimv2")
    Local $colDiskDrives = $objWMIService.ExecQuery("SELECT * FROM Win32_DiskDrive")
    If ($sBus = Default or Not $sBus) Then $sBus = "USB"

    For $objDrive In $colDiskDrives
        If $objDrive.InterfaceType <> $sBus then Continueloop
        ConsoleWrite( "Physical Disk: " & $objDrive.Caption & " -- " & $objDrive.DeviceID & " (" & $objDrive.InterfaceType & ")" &  @CRLF)
        $strDeviceID = StringReplace($objDrive.DeviceID, "\", "\\")
        ConsoleWrite( $objDrive.DeviceID & " = " & $objDrive.PNPDeviceID & @CRLF)
        Local $colPartitions = $objWMIService.ExecQuery( "ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" & _
                $strDeviceID & """} WHERE AssocClass = Win32_DiskDriveToDiskPartition" )
        For $objPartition In $colPartitions
            ConsoleWrite( "Disk Partition: " & $objPartition.DeviceID & @CRLF)
            Local $colLogicalDisks = $objWMIService.ExecQuery( "ASSOCIATORS OF {Win32_DiskPartition.DeviceID=""" & _
                    $objPartition.DeviceID & """} WHERE AssocClass = Win32_LogicalDiskToPartition" )
            For $objLogicalDisk In $colLogicalDisks
                ConsoleWrite( "Logical Disk: " & $objLogicalDisk.DeviceID & @CRLF)
            Next
        Next
    Next
EndFunc

Credit:

Also check out this thread

 

1 person likes this

Share this post


Link to post
Share on other sites

#3 ·  Posted

Thanks @InunoTaishou !

This is useful, but it is using WMI. I do not like WMI, because my script in winPE. Do you have any other way ?.

Share this post


Link to post
Share on other sites

#4 ·  Posted

Hello again meoit :)

Your request is a bit strange. What are you trying to do with this? Maybe there is a better solution? :)

If your 2 HDD are plugged with USB, the only thing that can detect one from the other is the size and the model.

1 person likes this

Share this post


Link to post
Share on other sites

#5 ·  Posted

Hi meoit,

you'll need _WinAPI_GetDriveBusType()

The drive should be both

  • $DRIVE_BUS_TYPE_USB
  • $DRIVE_BUS_TYPE_1394 

If you want to be able run WMI commands you must first deploy the WinPE-WMI.cab  from Windows ADK to the boot image
might as well add these too:

  • WinPE-HTA.cab
  • WinPE-MDAC.cab
  • WinPE-Scripting.cab
  •  
1 person likes this

Share this post


Link to post
Share on other sites

#6 ·  Posted

3 hours ago, Deye said:

Hi meoit,

you'll need _WinAPI_GetDriveBusType()

The drive should be both

  • $DRIVE_BUS_TYPE_USB
  • $DRIVE_BUS_TYPE_1394 

Thanks @Deye !!!.

I used:

DriveGetType('X:', $DT_BUSTYPE) --> result USB

DriveGetType('Y:', $DT_BUSTYPE) --> result USB

X: = my USB Fixed Disk (not Removable Disk)

Y: = my External HDD (HDD-Box, SSD-Box)

They give same result (is USB Bus type).

So, really hard for me.

Someone give me other way...

Thanks.

Share this post


Link to post
Share on other sites

#7 ·  Posted

#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>

Local $aArray = DriveGetDrive($DT_ALL)
Local $Return
If @error Then
    ; An error occurred when retrieving the drives.
    MsgBox($MB_SYSTEMMODAL, "", "It appears an error occurred.")
Else
    For $i = 1 To $aArray[0]
        $iBus1 = _WinAPI_GetDriveBusType($aArray[$i])
        $iBus2 = DriveGetType($aArray[$i], 3)
        $iBus3 = DriveGetType($aArray[$i])
        $Return &= @CRLF & StringUpper($aArray[$i]) & ' - ' & $iBus3 & @CRLF & " type : " & $iBus2 & @CRLF & " # " & $iBus1 & @CRLF
    Next
EndIf
;~ ClipPut($Return)
MsgBox(0, '', $Return)

if you can't differentiate anything from this you can try this UDF

1 person likes this

Share this post


Link to post
Share on other sites

#8 ·  Posted

Thanks @Deye !.

This code is give same result of DriveGetType.

Someone help me. Thanks all.

Share this post


Link to post
Share on other sites

#9 ·  Posted

On 5/14/2017 at 2:13 AM, Neutro said:

Hello again meoit :)

Your request is a bit strange. What are you trying to do with this? Maybe there is a better solution? :)

If your 2 HDD are plugged with USB, the only thing that can detect one from the other is the size and the model.

Thanks for your recommendation.

But it's not accurate, if I have an 80GB external hard drive and a 128GB usb fixed disk; Or 128GB external hard drive and a 128GB usb fixed disk.... and so on...

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

WMI - Win32_LogicalDisks

Drive Types:

 2 = "Removable disk"

  3="Fixed local disk"

  4="Network disk"

  5 = "Compact disk"

 

Turn the WMI quiery into a Autoit script

 

You can prune this down as needed.

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"

$Output=""
$Output = $Output & "Computer: " & $strComputer  & @CRLF
$Output = $Output & "==========================================" & @CRLF
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
   For $objItem In $colItems
      $Output = $Output & "Access: " & $objItem.Access & @CRLF
      $Output = $Output & "Availability: " & $objItem.Availability & @CRLF
      $Output = $Output & "BlockSize: " & $objItem.BlockSize & @CRLF
      $Output = $Output & "Caption: " & $objItem.Caption & @CRLF
      $Output = $Output & "Compressed: " & $objItem.Compressed & @CRLF
      $Output = $Output & "ConfigManagerErrorCode: " & $objItem.ConfigManagerErrorCode & @CRLF
      $Output = $Output & "ConfigManagerUserConfig: " & $objItem.ConfigManagerUserConfig & @CRLF
      $Output = $Output & "CreationClassName: " & $objItem.CreationClassName & @CRLF
      $Output = $Output & "Description: " & $objItem.Description & @CRLF
      $Output = $Output & "DeviceID: " & $objItem.DeviceID & @CRLF
      $Output = $Output & "DriveType: " & $objItem.DriveType & @CRLF
      $Output = $Output & "ErrorCleared: " & $objItem.ErrorCleared & @CRLF
      $Output = $Output & "ErrorDescription: " & $objItem.ErrorDescription & @CRLF
      $Output = $Output & "ErrorMethodology: " & $objItem.ErrorMethodology & @CRLF
      $Output = $Output & "FileSystem: " & $objItem.FileSystem & @CRLF
      $Output = $Output & "FreeSpace: " & $objItem.FreeSpace & @CRLF
      $Output = $Output & "InstallDate: " & WMIDateStringToDate($objItem.InstallDate) & @CRLF
      $Output = $Output & "LastErrorCode: " & $objItem.LastErrorCode & @CRLF
      $Output = $Output & "MaximumComponentLength: " & $objItem.MaximumComponentLength & @CRLF
      $Output = $Output & "MediaType: " & $objItem.MediaType & @CRLF
      $Output = $Output & "Name: " & $objItem.Name & @CRLF
      $Output = $Output & "NumberOfBlocks: " & $objItem.NumberOfBlocks & @CRLF
      $Output = $Output & "PNPDeviceID: " & $objItem.PNPDeviceID & @CRLF
      $strPowerManagementCapabilities = $objItem.PowerManagementCapabilities(0)
      $Output = $Output & "PowerManagementCapabilities: " & $strPowerManagementCapabilities & @CRLF
      $Output = $Output & "PowerManagementSupported: " & $objItem.PowerManagementSupported & @CRLF
      $Output = $Output & "ProviderName: " & $objItem.ProviderName & @CRLF
      $Output = $Output & "Purpose: " & $objItem.Purpose & @CRLF
      $Output = $Output & "QuotasDisabled: " & $objItem.QuotasDisabled & @CRLF
      $Output = $Output & "QuotasIncomplete: " & $objItem.QuotasIncomplete & @CRLF
      $Output = $Output & "QuotasRebuilding: " & $objItem.QuotasRebuilding & @CRLF
      $Output = $Output & "Size: " & $objItem.Size & @CRLF
      $Output = $Output & "Status: " & $objItem.Status & @CRLF
      $Output = $Output & "StatusInfo: " & $objItem.StatusInfo & @CRLF
      $Output = $Output & "SupportsDiskQuotas: " & $objItem.SupportsDiskQuotas & @CRLF
      $Output = $Output & "SupportsFileBasedCompression: " & $objItem.SupportsFileBasedCompression & @CRLF
      $Output = $Output & "SystemCreationClassName: " & $objItem.SystemCreationClassName & @CRLF
      $Output = $Output & "SystemName: " & $objItem.SystemName & @CRLF
      $Output = $Output & "VolumeDirty: " & $objItem.VolumeDirty & @CRLF
      $Output = $Output & "VolumeName: " & $objItem.VolumeName & @CRLF
      $Output = $Output & "VolumeSerialNumber: " & $objItem.VolumeSerialNumber & @CRLF
      if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop
      $Output=""
   Next
Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_LogicalDisk" )
Endif


Func WMIDateStringToDate($dtmDate)

    Return (StringMid($dtmDate, 5, 2) & "/" & _
    StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
    & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2))
EndFunc

 

Edited by ViciousXUSMC
1 person likes this

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Thanks @ViciousXUSMC

I can get Drive Types by using DriveGetType() :)

But my problem that I can not sort out where is the USB Fixed Disk (not Removable USB type), where is the External Hard Disk (call HDD-Box, SSD-Box or Portable Hard Disk). :|

Please do not give me WMI, because I use code for WinPE.

 

Edited by meoit

Share this post


Link to post
Share on other sites

#12 ·  Posted

I see now your trying to determine between two fixed disk, I thought you just needed to know witch was the removable one.

To the computer a USB HDD fixed type and a USB Flash Device fixed type are exactly the same.  There is no difference.

So you need to search for something that is different.

Be that partition size, volume name, etc. 

You may need to manually create the environment that offers the variables you need, say putting a simple .txt file in the root that is called "ExternalHDD.txt" then use simple .bat file setup for Dir / Find or AutoIT for FileList / StringinStr

Many ways to create your own variables to make this work.

1 person likes this

Share this post


Link to post
Share on other sites

#13 ·  Posted

The volume name is whoever wants to put the name of the set. If I base on that, I may go the wrong way.

Share this post


Link to post
Share on other sites

#14 ·  Posted

It seems that you have not really given enough information for us to get a clear picture of what you need.

First you just said you had 2 drives connected to your laptop.

Now suddenly your in a PBE and you either have more than just 2 drives or there is more people involved than just you.

What is static and what is variable in your situation and exactly what are you doing or trying to do?

 

If at least one of your disks is constant, then going with a root file to search for seems like an easy solution. 

 

Share this post


Link to post
Share on other sites

#15 ·  Posted

meoit,

Whats the difference between a "USB Fixed Disk" and a "USB External HDD"?

A fixed drive is usually connected via SATA or IDE.

They are both connected to a USB port, which makes them both portable and external.

There is nothing fixed about them.
Right?


"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Share this post


Link to post
Share on other sites

#16 ·  Posted

Try it with _WinAPI_GetDriveType


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now