Answer the question
In order to leave comments, you need to log in
Find list of all active drives via GetLogicalDriveStrings?
Hello.
You need to find a list of all active drives via GetLogicalDriveStrings. I found this code on nete:
Public Class Form1
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
ListBox1.Clear()
pos = 1
Do While Not Mid$(drives, pos, 1) = Chr(0)
drive = Mid$(drives, pos, 3)
pos = pos + 4
ListBox1.AddItem(UCase(drive))
Loop
End Sub
End Class
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question