Jump to content

DriveGetDrive('REMOVABLE') - (Solution)


Recommended Posts

How to identify a removable drive interface - USB or FireWire?

Thanks.

$Drive = DriveGetDrive('REMOVABLE')
if IsArray($Drive) then
    for $i = 1 to $Drive[0]
        if ??? then
            ConsoleWrite($Drive[$i] & ' - USB')
        else
            ConsoleWrite($Drive[$i] & ' - FireWire')
        endif
    next
endif
Edited by Yashied
Link to comment
Share on other sites

I dont know if this could be of any use but ill throw it in anyway.

It was created by another member on this forum however I can not remember his name but all credit goes to him.

$DBT_DEVICEARRIVAL = "0x00008000"
$WM_DEVICECHANGE = 0x0219
$strComputer = "."
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
 $colEvents = $objWMIService.ExecNotificationQuery _
    ("Select * From __InstanceOperationEvent Within 5 Where " _
        & "TargetInstance isa 'Win32_LogicalDisk'")

While 1
$objEvent = $colEvents.NextEvent
    If $objEvent.TargetInstance.DriveType = 2 Then
         Select
              Case $objEvent.Path_.Class()="__InstanceCreationEvent"
         Consolewrite("Drive " & $objEvent.TargetInstance.DeviceId & "has been added." & @CR)
                     ;A Usb drive has been plugged in
              Case $objEvent.Path_.Class()="__InstanceDeletionEvent"
                     ConsoleWrite("Drive " & $objEvent.TargetInstance.DeviceId & "has been removed."& @CR)
                     ;A usb drive has been removed
         EndSelect
     EndIf
Wend
Edited by AwAke
Link to comment
Share on other sites

I dont know if this could be of any use but ill throw it in anyway.

It was created by another member on this forum however I can not remember his name but all credit goes to him.

$DBT_DEVICEARRIVAL = "0x00008000"
$WM_DEVICECHANGE = 0x0219
$strComputer = "."
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
 $colEvents = $objWMIService.ExecNotificationQuery _
    ("Select * From __InstanceOperationEvent Within 5 Where " _
        & "TargetInstance isa 'Win32_LogicalDisk'")

While 1
$objEvent = $colEvents.NextEvent
    If $objEvent.TargetInstance.DriveType = 2 Then
         Select
              Case $objEvent.Path_.Class()="__InstanceCreationEvent"
         Consolewrite("Drive " & $objEvent.TargetInstance.DeviceId & "has been added." & @CR)
                     ;A Usb drive has been plugged in
              Case $objEvent.Path_.Class()="__InstanceDeletionEvent"
                     ConsoleWrite("Drive " & $objEvent.TargetInstance.DeviceId & "has been removed."& @CR)
                     ;A usb drive has been removed
         EndSelect
     EndIf
Wend
Thanks, but this is not related to my question.
Link to comment
Share on other sites

I found the solution.

^_^

const $DRIVE_BUS_TYPE_UNKNOWN = 0x00 ; Unknown bus type
const $DRIVE_BUS_TYPE_SCSI = 0x01    ; Small computer system interface (SCSI)
const $DRIVE_BUS_TYPE_ATAPI = 0x02   ; AT Attachment Packet Interface (ATAPI)
const $DRIVE_BUS_TYPE_ATA = 0x03     ; Advanced technology attachment (ATA)
const $DRIVE_BUS_TYPE_1394 = 0x04    ; IEEE 1394
const $DRIVE_BUS_TYPE_SSA = 0x05     ; Serial storage architecture (SSA)
const $DRIVE_BUS_TYPE_FIBRE = 0x06   ; Fibre channel
const $DRIVE_BUS_TYPE_USB = 0x07     ; USB
const $DRIVE_BUS_TYPE_RAID = 0x08    ; Redundant array of independent disks (RAID)
const $DRIVE_BUS_TYPE_ISCSI = 0x09   ; iSCSI
const $DRIVE_BUS_TYPE_SAS = 0x0A     ; Serial-attached SCSI
const $DRIVE_BUS_TYPE_SATA = 0x0B    ; Serial ATA
const $DRIVE_BUS_TYPE_SD = 0x0C      ; Secure digital
const $DRIVE_BUS_TYPE_MMC = 0x0D     ; Multimedia card

const $tagSTORAGE_PROPERTY_QUERY = _
      'dword PropertyId;' & _
      'dword QueryType;' & _
      'byte  AdditionalParameters[4]'

const $tagSTORAGE_DEVICE_DESCRIPTOR = _
      'ulong Version;' & _
      'ulong Size;' & _
      'byte  DeviceType;' & _
      'byte  DeviceTypeModifier;' & _
      'byte  RemovableMedia;' & _
      'byte  CommandQueueing;' & _
      'ulong VendorIdOffset;' & _
      'ulong ProductIdOffset;' & _
      'ulong ProductRevisionOffset;' & _
      'ulong SerialNumberOffset;' & _
      'dword BusType;' & _
      'ulong RawPropertiesLength;' & _
      'byte  RawDeviceProperties[512]'

func _DriveBusType($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_DEVICE_DESCRIPTOR = DllStructCreate($tagSTORAGE_DEVICE_DESCRIPTOR)
    local $tSTORAGE_PROPERTY_QUERY = DllStructCreate($tagSTORAGE_PROPERTY_QUERY)
    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
        $Ret = DllStructGetData($tSTORAGE_DEVICE_DESCRIPTOR, 'BusType')
    endif
    DllCall('kernel32.dll', 'int', 'CloseHandle', 'hwnd', $hDevice)
    return SetError(3 * ($Ret < 0), 0, $Ret)
endfunc; _DriveBusType

MsgBox(0, 'Test', _DriveBusType('G'))
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...