Código
Option Explicit '--------------------------------------------------------------------------------------- ' Module : mNativeEnumDrives ' Author : Karcrack ' Date : 11/02/2010 ' Purpose : Enumerate Drives, allow filtering by device type '--------------------------------------------------------------------------------------- 'NTDLL Private Declare Function NtQueryInformationProcess Lib "NTDLL" (ByVal hProcess As Long, ByVal ProcessInformationClass As Long, ProcessInformation As Any, ByVal ProcessInformationLength As Long, ReturnLength As Long) As Long Private Type PROCESS_DEVICEMAP_INFORMATION DriveMap As Long DriveType(1 To 32) As Byte End Type Public Enum DeviceType DRIVE_NOFILTER = -1 DRIVE_UNKNOWN DRIVE_NO_ROOT_DIR DRIVE_REMOVABLE DRIVE_FIXED DRIVE_REMOTE DRIVE_CDROM DRIVE_RAMDISK End Enum Private Const ProcessDeviceMap = 23 Public Function NtGetDrives(Optional ByVal lFilterType As DeviceType = DRIVE_NOFILTER) As Collection Dim tPDC As PROCESS_DEVICEMAP_INFORMATION Dim i As Long Set NtGetDrives = New Collection If NtQueryInformationProcess(-1, ProcessDeviceMap, tPDC, Len(tPDC), ByVal 0&) = 0 Then For i = 0 To 25 If tPDC.DriveMap And 2 ^ i Then If (lFilterType = -1) Or (tPDC.DriveType(i + 1) = lFilterType) Then NtGetDrives.Add Chr$(65 + i) & ":\" End If End If Next i End If End Function
Simplemente es una modificación de este código:
http://www.advancevb.com.ar/?p=335
Ejemplo de uso:
Código
Private Sub Form_Load() Dim vItem As Variant For Each vItem In NtGetDrives(DRIVE_REMOVABLE) MsgBox vItem Next vItem End Sub
Mostrará las unidades extraibles!
Hay que tener en cuenta que no todos los PenDrives USB son detectados como unidades extraibles, para mas precision mirar este codigo que saca el BusType:
http://www.advancevb.com.ar/?p=345
Cualquier duda preguntar!
Saludos!