Well hi! I found sume code in VB6- but converted it to VB.NET 2010. The program puts all of your drives into a listbox but its only the letter name, how can i get the drive name too? Here is my code:
Code:Public Class Form1 Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Integer, ByVal lpBuffer As String) As Integer Private Function GetDriveStrings() As String Dim result As Integer Dim strDrives As String Dim lenStrDrives As Integer result = GetLogicalDriveStrings(0, strDrives) strDrives = New String(Chr(0), result) lenStrDrives = result result = GetLogicalDriveStrings(lenStrDrives, strDrives) If result = 0 Then GetDriveStrings = "" Else GetDriveStrings = strDrives End If End Function Private Sub DisplayDriveTypes(ByRef drives As String) Dim pos As Integer Dim drive As String List1.Items.Clear() pos = 1 Do While Not Mid(drives, pos, 1) = Chr(0) drive = Mid(drives, pos, 3) pos = pos + 4 List1.Items.Add("(" & UCase(drive) & ")") Loop End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim strDrives As String strDrives = GetDriveStrings() If strDrives = "" Then MsgBox("No Drives were found!", MsgBoxStyle.Critical) Else DisplayDriveTypes(strDrives) End If End Sub End Class




Reply With Quote
