|
Получение имен всех логических дисков |
|
|
Очередной пример из серии "как определить имена всех дисков в системе". Причина появления этого примера - использование API-функции GetLogicalDriveStrings Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias
"GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As
String) As Long
Private Function GetDriveStrings() As String
Dim result As Long ' Result of our api calls
Dim strDrives As String ' String to pass to api call
Dim lenStrDrives As Long ' Length of the above string
result = GetLogicalDriveStrings(0, strDrives)
strDrives = String(result, 0)
lenStrDrives = result
result = GetLogicalDriveStrings(lenStrDrives, strDrives)
If result = 0 Then
GetDriveStrings = ""
Else
GetDriveStrings = strDrives
End If
End Function
Private Sub Command1_Click()
Dim strDrives As String
strDrives = GetDriveStrings()
If strDrives = "" Then
MsgBox "No Drives were found!", vbCritical
Else
DisplayDriveTypes strDrives
End If
End Sub
Private Sub DisplayDriveTypes(drives As String)
Dim pos As Long
Dim drive As String
List1.Clear
pos = 1
Do While Not Mid$(drives, pos, 1) = Chr(0)
drive = Mid$(drives, pos, 3)
pos = pos + 4
List1.AddItem UCase(drive)
Loop
End Sub
|
|
|
|
|
|
|