EnumDisk




Private Declare Function GetLogicalDriveStrings Lib "kernel32" _
Alias "GetLogicalDriveStringsA" _
(ByVal nBufferLength As Long, ByVal lpBuffer As String) _
As Long
'Utilizzo della funzione


Private Sub Command1_Click()
Dim colDrives As New Collection
Dim varDrive As Variant
If VbGetDrivesByString(colDrives) > 0 Then
For Each varDrive In colDrives
Debug.Print varDrive
Next
End If
End Sub

'la funzione restituisce il numero delle unita' trovate


Function VbGetDrivesByString(colDrives As Collection) _
As Integer
Dim strBuffer As String
Dim lngBytes As Long
Dim intPos As Integer
Dim intPos2 As Integer
Dim strDrive As String
Set colDrives = New Collection
strBuffer = Space(255)
lngBytes = GetLogicalDriveStrings(Len(strBuffer), strBuffer)
intPos2 = 1
intPos = InStr(intPos2, strBuffer, vbNullChar)
Do Until intPos = 0 Or intPos > lngBytes
strDrive = Mid(strBuffer, intPos2, intPos - intPos2)
colDrives.Add strDrive, strDrive
intPos2 = intPos + 1
intPos = InStr(intPos2, strBuffer, Chr(0))
Loop
VbGetDrivesByString = colDrives.Count
End Function











( enumdisk.html )- by Paolo Puglisi - Modifica del 17/12/2023