Sign in to follow this  
Followers 0
Yashied

_DriveGetBusType()

2 posts in this topic

Func _DriveGetBusType($DriveLetter)

    Local $Ret

    $Ret = DllCall('kernel32.dll', 'hwnd', 'CreateFile', _
            'str', '\\.\' & $DriveLetter & ':', _
            'dword', 0, _
            'dword', 0, _
            'ptr', 0, _
            'dword', 3, _
            'dword', 128, _
            'ptr', 0 _
            )

    If @error Then
        Return SetError(1, 0, -1)
    EndIf
    If $Ret[0] = 0xFFFFFFFF Then
        Return SetError(2, 0, -1)
    EndIf

    Local $tSTORAGE_PROPERTY_QUERY = DllStructCreate('dword;dword;byte[4]')
    Local $tSTORAGE_DEVICE_DESCRIPTOR = DllStructCreate('ulong;ulong;byte;byte;byte;byte;ulong;ulong;ulong;ulong;dword;ulong;byte[512]')
    Local $hDevice = $Ret[0]

    $Ret = DllCall('kernel32.dll', 'int', 'DeviceIoControl', _
            'hwnd', $hDevice, _
            'dword', 0x002D1400, _
            'ptr', DllStructGetPtr($tSTORAGE_PROPERTY_QUERY), _
            'dword', DllStructGetSize($tSTORAGE_PROPERTY_QUERY), _
            'ptr', DllStructGetPtr($tSTORAGE_DEVICE_DESCRIPTOR), _
            'dword', DllStructGetSize($tSTORAGE_DEVICE_DESCRIPTOR), _
            'dword*', 0, _
            'ptr', 0 _
            )

    If (@error) Or ($Ret[0] = 0) Then
        $Ret = -1
    Else
        Switch DllStructGetData($tSTORAGE_DEVICE_DESCRIPTOR, 11)
            Case 0x00
                $Ret = 'UNKNOWN' ; Unknown bus type
            Case 0x01
                $Ret = 'SCSI' ; Small computer system interface (SCSI)
            Case 0x02
                $Ret = 'ATAPI' ; AT Attachment Packet Interface (ATAPI)
            Case 0x03
                $Ret = 'ATA' ; Advanced technology attachment (ATA)
            Case 0x04
                $Ret = '1394' ; IEEE 1394
            Case 0x05
                $Ret = 'SSA' ; Serial storage architecture (SSA)
            Case 0x06
                $Ret = 'FIBRE' ; Fibre channel
            Case 0x07
                $Ret = 'USB' ; USB
            Case 0x08
                $Ret = 'RAID' ; Redundant array of independent disks (RAID)
            Case 0x09
                $Ret = 'ISCSI' ; iSCSI
            Case 0x0A
                $Ret = 'SAS' ; Serial-attached SCSI
            Case 0x0B
                $Ret = 'SATA' ; Serial ATA
            Case 0x0C
                $Ret = 'SD' ; Secure digital
            Case 0x0D
                $Ret = 'MMC' ; Multimedia card
        EndSwitch
    EndIf
    DllCall('kernel32.dll', 'int', 'CloseHandle', 'hwnd', $hDevice)
    Return SetError(3 * ($Ret < 0), 0, $Ret)
EndFunc   ;==>_DriveGetBusType

; Example

Local $Drive = DriveGetDrive('ALL')

For $i = 1 To $Drive[0]
    ConsoleWrite(StringUpper($Drive[$i]) & ' => ' & _DriveGetBusType(StringLeft($Drive[$i], 1)) & @CR)
Next

Share this post


Link to post
Share on other sites



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
Sign in to follow this  
Followers 0