Jump to content
DigDeep

Detect External Hard Drive connected to the USB Drive

Recommended Posts

DigDeep

Hi,

I am in need of some urgent help please.

I am trying to detect how many Partitions are available on the FIXED Internal Drive. Unfortunately, if I am connecting an external Hard Drive via USB, it will be still showing as FIXED Drive.

Can someone please help in getting this fixed ASAP. 

Note: My purpose is to only detect the number of partitions made on the Internal Hard Drives and exclude anything detected as USB Drive.

I see many forums have discussed some or the other sort of this already but I am not able to get any of them

Thanks.

#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>

Local $aArray = DriveGetDrive($DT_FIXED)

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]
        If $i & "/" & $aArray[0] > 1 / 1 Then
            Local $dt = DriveGetType($aArray[$i])
            If $dt = $DT_BUSTYPE And $aArray[$i] <> "C:" Then
                MsgBox($MB_SYSTEMMODAL, "", "Additional Drive (" & $dt & "): " & $i & "/" & $aArray[0] & ":" & @CRLF & StringUpper($aArray[$i])) ; Display if Drive letter is USB
            Else
                MsgBox($MB_SYSTEMMODAL, "", "Drive (" & $dt & ") = " & $aArray[$i])
            EndIf
        EndIf
    Next
EndIf

 

Share this post


Link to post
Share on other sites
mikell

You might first use :  If DriveGetType($disk, $DT_BUSTYPE) <> "USB" Then...
and then check the partitions using WMI
 

Share this post


Link to post
Share on other sites
DigDeep

Thanks @mikell

I did it this way and got it fixed.

#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>

Local $aArray = DriveGetDrive($DT_FIXED)

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]
        If $i & "/" & $aArray[0] > 1 / 1 Then
            Local $dt = DriveGetType($aArray[$i], $DT_BUSTYPE)
                    If $dt = "USB" Then
                MsgBox($MB_SYSTEMMODAL, "", "USB Drive (" & $dt & "): " & $i & "/" & $aArray[0] & ":" & @CRLF & StringUpper($aArray[$i])) ; Display if Drive letter is USB
            Else
                MsgBox($MB_SYSTEMMODAL, "", "Internal Drive (" & $dt & ") = " & $aArray[$i])
            EndIf
        EndIf
    Next
EndIf

 

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

×