1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| Imports System.Management
Public Class Form1
Public Enum DriveType
Inconnu = 0
NoRootDirectory = 1
Amovible = 2
HardDisk = 3
NetworkDrive = 4
CDROM = 5
RamDisk = 6
End Enum
Public Function GetDriveType(ByVal strDrive As String) As DriveType
strDrive = "Win32_LogicalDisk='" & strDrive.Substring(0, 2) & "'"
Dim moDisk As ManagementObject = New ManagementObject(strDrive)
Return DirectCast([Enum].Parse(GetType(DriveType), moDisk("DriveType").ToString()), DriveType)
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim astrDrives() As String = Environment.GetLogicalDrives()
Dim strDrive As String
For Each strDrive In astrDrives
If GetDriveType(strDrive) = 5 Then
MsgBox(strDrive)
Exit For
End If
Next strDrive
End Sub
End Class |